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">
<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.
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.
Hie, I followed your approach and it has worked. Thank you so much.
Could you please help with how we can make this sdk style project to sync and work with Xcode just like xamarin.ios projects
Hi! Do you mean like when you edit storyboards in Xcode? I’m not too sure how that works in .NET 6. I would try to reach out to the product team on f.ex. Twitter on that one
Hey,
I have just migrated to .Net iOS project – new packages etc and my app was rejected from the App Store with a message : The app references non-public symbols in MyAppName: _ubrk_openRules, _ucal_add, _ucal_close, _ucal_get, _ucal_getAttribute.. Seems like some updated nuget package is causing the issue since my code does not contain method names as such. Searched the web and cannot find anything that can help me identify the problematic package.
If you could please share a helping hand it would be great.
Thanks very much
Hi, I haven’t experienced those errors myself so I can’t say what’s wrong here. Maybe there are some linker settings that are too eager when building in Release? Maybe you could test/replicate it through Testflight or App Center or something.