Home > Net >  How to update a plain Xamarin.iOS solution (without Xamarin Forms) to .net 6 (without MAUI) to run o
How to update a plain Xamarin.iOS solution (without Xamarin Forms) to .net 6 (without MAUI) to run o

Time:05-03

I have a Xamarin.iOS solution that includes a library project and an executable. The solution does not use Xamarin Forms, i.e., it is a so-called "Xamarin Native" solution.

I'd like to upgrade this to a .net 6 solution. Unfortunately, all the examples and documentation I've seen only explain how to upgrade a Xamarin Forms solution to a .net 6 solution that uses MAUI (which is the evolution of Xamarin Forms.)

So:

  1. How do I update my solution to a .net 6 "native" iOS solution?
  2. Since .net 6 also supports Mac Catalyst, how can I configure my solution to also run on Mac Catalyst in addition to iOS?

CodePudding user response:

Approach #1:
iOS Application (Preview)

Looking at the available types of VS projects, you could do: VS 2022 Preview / New Project / language=c#, platform=ios. Scroll near bottom of list, select iOS Application (Preview). Then in Solution Explorer, rt-click on project / Properties. The result targets ".NET 6.0" and "iOS" - which you want.

Looking at .csproj, it has the expected <TargetFramework>net6.0-ios</TargetFramework>.
You could manually add ;net6.0-maccatalyst.

BUT:

  • the folders aren't set up for multi-targetting.
  • That might by a symptom that there are other missing lines of code and xml settings related to multi-targetting.
  • [Optional] Even though you aren't using Maui for UI, it might be useful to use Maui.Essentials. I think there is something that needs to be added to the app startup process, to initialize that.

I don't recommend Approach #1 at this time - especially since you wish to target Mac also; you have to know what you are doing to get everything organized in a manner that streamlines your development process.

Unless someone can point to detailed instructions for running multi-platform net6 without Maui.


Approach #2: Maui Application (Preview). Then delete everything you don't need given that you aren't using Maui UI.

Personally I would do this for now, to get code running on both iOS and Mac. Once you see it working, you can get aggressive about deleting stuff.

  • Modify the startup code in iOS and Mac folders. Start a "native" root viewcontroller, instead of maui app builder. Just like you do today in Xamarin.iOS.

You could defer deleting Maui UI code and references, until a finalized Maui release. At that time, the multi-platform net6 should be easier to get at, without relying on Maui framework.

Bottom line: Feels like multi-platform net6 hasn't been emphasized (short-term), except as part of Maui. Even though net6 on iOS (and other platforms) does stand on its own in the code base. So "go with the flow" until everything is solid.

  • Related