如何将普通的Xamarin.ios解决方案(没有Xamarin表格)更新为.NET 6(无MAUI)以在iOS和MAC催化剂上运行?

发布于 2025-01-25 20:03:39 字数 332 浏览 2 评论 0原文

我有一个Xamarin.ios解决方案,其中包括一个库项目和可执行文件。该解决方案不使用Xamarin形式,即,它是所谓的“ Xamarin Native”解决方案。

我想将其升级到.NET 6解决方案。不幸的是,我所看到的所有示例和文档都仅解释了如何将Xamarin Formes solument升级到使用MAUI的.NET 6解决方案(这是Xamarin表单的演变)。

因此:

  1. 我如何将解决方案更新为a。 NET 6“本机” iOS解决方案?
  2. 由于.NET 6也支持MAC Catalyst,因此除了iOS之外,我还能配置我的解决方案以在MAC催化剂上运行?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謌踐踏愛綪 2025-02-01 20:03:39

方法1:
ios应用程序(预览)< / code>

查看可用类型的vs projects < / code>,您可以做:vs 2022 Preview / new Project / new Project / Language = C#,Platform = ios。滚动在列表的底部附近,选择ios应用程序(预览)。然后在解决方案资源管理器中,对项目 /属性单击rt键。结果目标是“ .NET 6.0”和“ iOS” - 您想要的。

查看.csproj,它具有预期的&lt; targetFramework&gt; net6.0-ios&lt;/targetFramework&gt;
您可以手动添加; Net6.0-Maccatalyst

但是:

  • 这些文件夹不是用于多目标的设置。
  • 这可能会出于症状,即与多目标有关的代码和XML设置缺失。
  • [可选]即使您不为UI使用MAUI,使用maui.sentenations也可能很有用。我认为需要将某些内容添加到应用程序启动过程中,以初始化。

我目前不建议使用#1的方法 - 特别是因为您也希望针对Mac;您必须知道自己在做什么,以使您的一切都精简您的开发过程。

除非有人可以指向不使用MAUI的多平台Net6运行的详细说明。


方法2:
MAUI应用程序(预览)。然后删除您不需要使用Maui UI的所有内容。

就我个人而言,我现在会这样做,以使iOS和MAC上的代码同时运行。一旦看到它起作用,您就可以对删除内容进行积极进取。

  • 修改iosmac文件夹中的启动代码。启动一个“本机” root ViewController,而不是毛伊岛应用程序构建器。就像您今天在xamarin.ios中所做的一样。

您可以删除MAUI UI代码和参考文献,直到最终确定的MAUI版本。当时,多平台net6应该在不依赖MAUI框架的情况下更容易获得。

底线:感觉像多平台net6尚未强调(短期),除非是毛伊岛的一部分。即使iOS (和其他平台)上的net6确实在代码库中独立存在。因此,“顺其自然”,直到一切都扎实。

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.

雾里花 2025-02-01 20:03:39

我设法升级到.net7:

  1. 升级库(取决于iOS)CSPROJ到新格式:
 &lt; project SDK =“ Microsoft.net.sdk”&gt; 
  &lt; PropertyGroup&gt; 
    &lt; targetFrameWorks&gt; net7.0-ios; net7.0-maccatalyst&lt;/targetFrameWorks&gt; 
    &lt; outputType&gt; library&lt;/outputType&gt; gt; 
    &lt; assemblyName&gt; myassemblyName&lt;/gashingBlyName&gt; gt; gt; gt; gt; 
    &lt; supportEdoSplatFormversion条件=“ $([msbuild] :: getTargetPlatFormidentifier('$(targetFrameWork)'))
=='ios'”&gt; 12.0&lt;/supportedOsplatFormversion&gt; 
    &lt; supportEdoSplatFormversion条件=“ $([msbuild] :: getTargetPlatFormidentifier('$(targetFrameWork)'))
=='MacCatalyst'“”&gt; 13.1&lt;/supportEdoSplatFormversion&gt; 
  &lt;/propertyGroup&gt;
...
&lt;/project&gt;
 
  1. 升级您的应用程序CSPROJ:
 &lt; project SDK =“ Microsoft.net.sdk”&gt;   
  &lt; PropertyGroup&gt;
    &lt; targetFrameWorks&gt; net7.0-ios; net7.0-maccatalyst&lt;/targetFrameWorks&gt;
    &lt; outputType&gt; exe&lt;/outputType&gt;
    &lt; usemaui&gt; true&lt;/usemaui&gt;
    &lt; singleproject&gt; true&lt;/singleproject&gt;
    ...
    &lt; supportEdoSplatFormversion条件=“ $([msbuild] :: getTargetPlatFormIdentifier('$('$(targetFrameWork)'))=='ios'“”&gt; 13.0&lt;/supportedOsplatformversion&gt; gt;
    &lt; supportEdoSplatFormVersion条件=“ $([msbuild] :: getTargetPlatFormIndentifier('$(targetFramework)'))=='macCatalyst''&gt; 14.0&lt;/supportededosplatformversion&gt; gt;         
    &lt; applicationTitle&gt; myApptitle&lt;/applicationTitle&gt; gt;
    &lt; applicationId&gt; abc&lt;/applicationId&gt; gt;
    &lt; applicationIdguid&gt; aaadfffffaa ....&lt;/applicationIdguid&gt; gt;
    &lt; applicationDisplayversion&gt; 12.0&lt;/applicationDisplayversion&gt; gt;
    &lt; applicationVersion&gt; 12.0.0&lt;/applicationVersion&gt;   
  &lt;/propertyGroup&gt;
 ...
 &lt;/project&gt;
 

2.2从CSPROJ和所有XIB,情节板文件中删除所有.CS文件。或者不要添加它们,它们会被添加。

2.3使用上下文菜单更改所有XIB,故事板文件将操作构建为“接口定义”。

  1. 从info.plist中删除Min OS键值(因为现在在CSPROJ中)。

3.1更改信息。
从ARMV7到
ARM64

3.2从MacCatalyst Info.plist

  1. 创建文件夹平台/iOS和Platforms/MacCatalyst中删除lsrequiresiphoneos。移动并重复info.plist到这些文件夹。 (否则,您将无法使用常规(应用程序)视图编辑信息。

  2. 即使它说我们使用毛伊岛,我们实际上并不使用毛伊岛,但它允许我们使用Multitarget应用程序。如果您将其删除,则无法选择催化剂目标进行部署。您可以使用另一种方法,即复制App Csproj并仅在第二个CSPROJ中留下催化剂的目标。

  3. 将平台特定代码放在上面的文件夹中,它们可能具有相同的类名称和签名,并且仅针对特定平台进行编译。

I managed to upgrade to .net7:

  1. Upgrade libraries (which depends on iOS) csproj to new format:
<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>
  1. Upgrade your app csproj:
<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'.

  1. Remove min os key-value from info.plist (Because it is now in csproj).

3.1 Change info.plist UIRequiredDeviceCapabilities
from armv7 to
arm64

3.2 Remove LSRequiresIPhoneOS from maccatalyst info.plist

  1. 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).

  2. 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.

  3. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文