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.
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"> <PropertyGroup> <TargetFramework>net6.0-ios</TargetFramework> <OutputType>Exe</OutputType> <Nullable>enable</Nullable> <ImplicitUsings>true</ImplicitUsings> <SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion> </PropertyGroup> </Project>
Once you do that, Visual Studio might give you the following warning:
To fix this, open the Configuration Manager – most easily accessed through the configuration dropdown:
Create a new solution platform from the dropdown (see screenshot):
Select “Any CPU”, Copy Settings from <Empty> and check the “Create new project platforms” box. Click OK.
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.
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).
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.
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.