Reputation: 4821
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:
Upvotes: 10
Views: 1179
Reputation: 9491
I managed to upgrade to .net7:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net7.0-ios;net7.0-maccatalyst</TargetFrameworks> <OutputType>Library</OutputType> <AssemblyName>MYASSEMBLYNAME</AssemblyName> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">12.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion> </PropertyGroup> ... </Project>
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net7.0-ios;net7.0-maccatalyst</TargetFrameworks> <OutputType>Exe</OutputType> <UseMaui>true</UseMaui> <SingleProject>true</SingleProject> ... <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))== 'ios'">13.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))== 'maccatalyst'">14.0</SupportedOSPlatformVersion> <ApplicationTitle>MYAPPTITLE</ApplicationTitle> <ApplicationId>a.b.c</ApplicationId> <ApplicationIdGuid>aaadfffffaa....</ApplicationIdGuid> <ApplicationDisplayVersion>12.0</ApplicationDisplayVersion> <ApplicationVersion>12.0.0</ApplicationVersion> </PropertyGroup> ... </Project>
2.2 Remove all .cs files from csproj and all xib, storyboard files. Or don't add them, they will be added theirselves.
2.3 Use context menu to change all xib, storyboard files build action to 'interface definition'.
3.1 Change info.plist UIRequiredDeviceCapabilities from armv7 to arm64
3.2 Remove LSRequiresIPhoneOS from maccatalyst info.plist
Create folders Platforms/iOS and Platforms/MacCatalyst. Move and duplicate info.plist into these folders. (Otherwise you won't be able to edit info plist with usual (Application) view).
Even though it says we use Maui we do not in fact use Maui, but it allows us to use, compile multitarget app. If you remove it you won't be able to choose Catalyst target to deploy. You may use another approach which is to duplicate app csproj and leave target only for Catalyst in second csproj it will also work.
Place platform specific code in the folders above, they may have the same class names and signatures and will be compiled only for specific platform.
Upvotes: 0
Reputation: 21341
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:
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.
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.
Upvotes: 4