Converting Xamarin.iOS template to .NET 6

Last week I wrote a post on how you can convert your Xamarin.Android template to .NET 6. A natural continuation of this is to see how we can do the same thing for a Xamarin.iOS project. The last post touches on the new templates and references some useful links, so I recommend you go check that out as well.

Upgrade csproj

Like with the Android project, we start by replacing the contents of our iOS csproj file with that of the content from a File -> New iOS Application Project. It will look like this:

<Project Sdk="Microsoft.NET.Sdk">

Once you do that, Visual Studio might give you the following warning:

Warning in the Solution Explorer.

To fix this, open the Configuration Manager – most easily accessed through the configuration dropdown:

Accessing Configuration Manager from the dropdown.

Create a new solution platform from the dropdown (see screenshot):

Creating a new solution platform.

Select “Any CPU”, Copy Settings from <Empty> and check the “Create new project platforms” box. Click OK.

New solution platform options.

Visual Studio might still show you a warning, but that should disappear on restarting Visual Studio. After that, make sure the newly “Any CPU” is selected from the configuration dropdown.

Optional: You can remove the iPhone and iPhoneSimulator configurations as we won’t be needing these anymore.

Now, connect to your Mac build host and verify that the iOS simulators appear in the dropdown.

Simulator now appearing in the dropdown.

Then we need to match the MinimumOSVersion (Deployment Target) in the Info.plist file with the SupportedOSPlatformVersion in the csproj file. In this example I set the Info.plist value equal to the one in the csproj file (13.0).

Setting the Deployment Target, aka. MinimumOSVersion, to 13.0.

Finally, we delete AssemblyInfo.cs (and the Properties folder), and boom! Your project should be able to build. Test it out by deploying to one of the simulators.

Final notes

As mentioned in the post for Android, you will have to check your project references and add back your NuGet packages after performing these steps. Also make sure that your NuGet packages target .NET 6 or replaces them with ones that does.

There’s a sample project on GitHub where I created a File -> New Xamarin.iOS Project and converted it to a .NET 6 application using these steps. Check out the commit history to see the steps I mentioned here.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.