如何将普通的Xamarin.ios解决方案(没有Xamarin表格)更新为.NET 6(无MAUI)以在iOS和MAC催化剂上运行?
我有一个Xamarin.ios解决方案,其中包括一个库项目和可执行文件。该解决方案不使用Xamarin形式,即,它是所谓的“ Xamarin Native”解决方案。
我想将其升级到.NET 6解决方案。不幸的是,我所看到的所有示例和文档都仅解释了如何将Xamarin Formes solument升级到使用MAUI的.NET 6解决方案(这是Xamarin表单的演变)。
因此:
- 我如何将解决方案更新为a。 NET 6“本机” iOS解决方案?
- 由于.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:
- How do I update my solution to a .net 6 "native" iOS solution?
- Since .net 6 also supports Mac Catalyst, how can I configure my solution to also run on Mac Catalyst in addition to iOS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法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
。但是:
maui.sentenations
也可能很有用。我认为需要将某些内容添加到应用程序启动过程中,以初始化。我目前不建议使用#1的方法 - 特别是因为您也希望针对Mac;您必须知道自己在做什么,以使您的一切都精简您的开发过程。
除非有人可以指向不使用MAUI的
多平台Net6
运行的详细说明。方法2:
MAUI应用程序(预览)
。然后删除您不需要使用Maui UI的所有内容。就我个人而言,我现在会这样做,以使iOS和MAC上的代码同时运行。一旦看到它起作用,您就可以对删除内容进行积极进取。
ios
和mac
文件夹中的启动代码。启动一个“本机” 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, selectiOS 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
andMac
folders. Start a "native" root viewcontroller, instead of maui app builder. Just like you do today inXamarin.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 thoughnet6 on iOS
(and other platforms) does stand on its own in the code base. So "go with the flow" until everything is solid.我设法升级到.net7:
2.2从CSPROJ和所有XIB,情节板文件中删除所有.CS文件。或者不要添加它们,它们会被添加。
2.3使用上下文菜单更改所有XIB,故事板文件将操作构建为“接口定义”。
3.1更改信息。
从ARMV7到
ARM64
3.2从MacCatalyst Info.plist
创建文件夹平台/iOS和Platforms/MacCatalyst中删除lsrequiresiphoneos。移动并重复info.plist到这些文件夹。 (否则,您将无法使用常规(应用程序)视图编辑信息。
即使它说我们使用毛伊岛,我们实际上并不使用毛伊岛,但它允许我们使用Multitarget应用程序。如果您将其删除,则无法选择催化剂目标进行部署。您可以使用另一种方法,即复制App Csproj并仅在第二个CSPROJ中留下催化剂的目标。
将平台特定代码放在上面的文件夹中,它们可能具有相同的类名称和签名,并且仅针对特定平台进行编译。
I managed to upgrade to .net7:
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.