Migrating Xamarin.Android & Xamarin.iOS Applications to .NET 6

Ruby Verma
3 min readJul 2, 2023

There is no better time to update and migrate your Xamarin.iOS and Xamarin.Android apps to .Net6. Every Microsoft product has an expiration date, including Xamarin. Microsoft will stop supporting all Xamarin SDKs by May 1, 2024. In order to continue supporting the project, you should migrate it as soon as possible. The migrating process will be quick and easy for most of the apps. You will be able to take advantage of .Net 6 or 7 features, and the application's performance will be better.

I have assembled the steps that will help you with migration. Let’s get started.

Step 1: Update Project Files

There are two ways to migrate:

A. Create a new .Net 6-style project using the project templates built into Visual Studio 2022 and copy-paste all the relevant files like source code, resources, NuGet dependencies, project references, etc. It is the simplest way to make the changes. If you have added anything special for your project in the .csproj file, make sure you add that too.

B. Edit your .csproj file to .Net 6 style, and you are good to go. Simply make the necessary edits to make it a legitimate SDK-style project.

Step 2: Analyze the NuGet packages

You will need to ensure that they have been updated and recompiled against .NET 6 or .NET 7 for iOS and Android. You can browse NuGet.org and see which frameworks your NuGet package supports. You might need to update to a new version of a NuGet package or find an alternative if the version is incompatible with the most recent framework.

In my project, I have the following references:

<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.8.0" />
</ItemGroup>

Find your packages and see which frameworks they support by visiting NuGet.org. In the case of Xamarin.AndroidX.AppCompat, we can see that it supports both monoandroid12.0 (Xamarin.Android) and net6.0-android31.0 (compiled against .NET 6).

In this case, this library is fully compatible with the latest versions of .NET for Android. If it’s not compatible, consider updating the version or finding an alternative.

Step 3: Android: Delete Resource.designer.cs

In Xamarin.Android projects, the designer generates a Resource.designer.cs file whenever any resource is changed or added inside the Resources folder. These files are no longer needed in the new project template. Simply delete those files.

Step 4: Delete AssemblyInfo.cs

Similar to the Resource.designer.cs file, AssemblyInfo.cs is also an auto-generated file based on project settings and is no longer needed. These files can be deleted from the Properties folder for both Android & iOS.

Step 5: Xamarin.Essentials to .NET MAUI Essentials

Xamarin.Essentials was a fundamental library for nearly every Xamarin application. If you were using this NuGet package, remove it as this is now part of .NET MAUI. You can add MAUI by adding the following lines in your .csproj file:

<PropertyGroup>
<UseMauiEssentials>true</UseMauiEssentials>
</PropertyGroup>

Once you update to .NET MAUI Essentials, you will need to update any ‘using Xamarin.Essentials;’ using statements to the new .NET MAUI Essentials namespaces, which you can find in the documentation.

Step 6: Add or Update Project References

If you reference any other .NET Standard libraries, you can add them as a project reference. It will also be necessary to update any class libraries or binding libraries to the new formats before adding them back as references. You may want to consider updating your .NET Standard libraries to .NET 6 or .NET 7 to take advantage of the latest features of .NET and C#.

Summary

I hope that you found this guide helpful in migrating your Xamarin.iOS and Xamarin.Android applications. Consider reading the full migration documentation for more information.

Check out the full before and after code samples on my GitHub.

Do read the Xamarin support policy to plan upgrades and migration for your application.

References

--

--