英文:
Is there an upgrade path from Xamarin for Mac to .NET MAUI?
问题
尽管 Xamarin Forms 应用程序有一个已记录的升级路径可以迁移到 .NET MAUI,但对于 Xamarin for Mac 来说似乎并没有这样的情况,而且对 Xamarin 的支持将在 2024 年 5 月结束。那么,Xamarin for Mac 桌面应用程序是否需要从头开始重新开发呢?我看不到将 C# 和链接到 XCode GUI 开发方式转换为 .NET MAUI 的方法。
已经搜索了将 Xamarin for Mac 应用程序升级到 .NET MAUI 的路径,但没有找到。
英文:
While there is a documented upgrade path for Xamarin Forms apps to .NET MAUI, this doesn't seem to be the case for Xamarin for Mac, and support for Xamarin is ending as of May 2024. Is it then the case that Xamarin for Mac desktop apps need to be redeveloped from scratch? I can't see any way of converting the C#/link to XCode GUI development approach to .NET MAUI.
Have searched for an upgrade path for Xamarin for Mac apps to .NET MAUI, but haven't found one.
答案1
得分: 3
从.NET 6开始,Xamarin native
API已被重新命名为.Net for (Platform name)
。
如果您只针对一个平台进行开发,您不需要使用Maui,您只需要针对该平台使用最新的.NET。
关键决策是您将编写“MacOS UI”、 “Maui UI” 还是“iOS/MacCatalyst UI”。
答案 #1: .Net Mac
(又名 .Net for Mac
):仅适用于MacOS
升级 Xamarin.Android、...、Xamarin.Mac 到 .Net:
> 对于大多数应用程序,您不需要更改命名空间或进行其他重写。
> 为了简化升级过程,我们建议创建一个与您的Xamarin native项目相同类型和名称的新.NET项目,然后复制您的代码进去。...
其他有用的链接:
下载 .Net 7.0. 用于开发时,选择与您正在开发的Mac CPU对应的其中一个MacOS的“SDK”。
答案 #2: Maui
:跨平台UI,包括Mac
注意:Maui
UI类似于Xamarin.Forms
UI;您的Xamarin.Mac
UI需要重新编写。 这与任何其他Xamarin native
平台代码一样。
Maui UI是跨平台UI类,支持XAML。(它可以完全使用C#编写;在底层是C#类,但大多数示例使用XAML。)
由于它是跨平台UI,据我所知,这种方法不支持Apple XCode/Storyboard/Nibs。
在Mac上运行Maui
(跨平台UI)的唯一方法是使用iOS/MacCatalyst
目标。
Mac Catalyst
来自Apple,允许iOS应用在Mac上运行。
iOS API和MacOS API之间存在很大的兼容性。然而,有一些限制;一些MacOS API无法从iOS/MacCatalyst中访问。
iOS特定的代码放在目录Platforms/iOS
中。
您现有的大多数Xamarin.Mac UI代码将被重写为该文件夹中的“自定义处理程序”。
答案 #3: .Net iOS
:通过Mac Catalyst支持Mac
第三种方法是通过开发iOS应用程序,在Mac上通过Mac Catalyst运行这些应用程序,以支持所有Apple设备。
这听起来很像第二种方法。不同之处在于您正在使用特定于iOS的UI类,并使用XCode开发iOS storyboard。
在文档和工具方面,这种方法似乎有些落后。
此时,除非出现更新的文档和示例,否则我建议选择第二种方法,但在Platforms/iOS
目录中更多地使用(如果您只关心Apple平台,则减少对跨平台UI的依赖)。 (还可以在.csproj
文件中添加一些自定义行,以创建iOSMacCatalyst
目录。)
英文:
Starting with .Net 6, the Xamarin native
APIs have been rebranded as .Net for (Platform name)
.
You don't need Maui, if you are only targetting one platform; all you need is the latest .Net, for that platform.
The essential decision is whether you will write "MacOS UI", or "Maui UI", or "iOS/MacCatalyst UI".
Answer #1: .Net Mac
(aka .Net for Mac
): just for MacOS
Upgrade Xamarin.Android, .., Xamarin.Mac to .Net:
> For most apps, you won't need to change namespaces or undertake other rewrites.
> To simplify the upgrade process, we recommend creating a new .NET project of the same type and name as your Xamarin native project, and then copying in your code. ...
Other useful links:
Download .Net 7.0. For development, pick one of the MacOS "SDK"s; the one that corresponds to the Mac cpu you are developing on.
Answer #2: Maui
: cross-platform UI including Mac
NOTE: Maui
UI is like Xamarin.Forms
UI; your Xamarin.Mac
UI would have to be rewritten. This is the same as from any other Xamarin native
platform code.
Maui UI is cross-platform UI classes, and supports XAML. (It can be completely written in C#; it is C# classes underneath, but most examples use XAML.)
Because it is cross-platform UI, AFAIK, this approach DOES NOT support Apple XCode/Storyboard/Nibs.
The only way to run Maui
(cross-platform UI) on a Mac, is to use the iOS/MacCatalyst
target.
Mac Catalyst
is from Apple, and allows iOS apps to run on a Mac.
There is a lot of compatibility between iOS APIs and MacOS APIs.
HOWEVER, there are some limitations; some MacOS APIs are not reachable from iOS/MacCatalyst.
iOS-specific code goes in directory Platforms/iOS
.
Most of your existing Xamarin.Mac UI code would get reworked into "custom handlers" in that folder.
Answer #3: .Net iOS
: support Mac via Mac Catalyst
The third approach is to support all Apple devices, by developing an iOS app, and running those on a Mac via Mac Catalyst.
This may sound a lot like #2. The difference is that you are using iOS-specific UI classes, and use XCode to develop the iOS storyboard.
This approach seems to be a bit behind, in documentation and tooling.
At this time, unless newer docs and examples come out, I would instead do #2, but with more use of Platforms/iOS
directory (less reliance on cross-platform UI, if you only care about Apple platforms). (Can also have an iOSMacCatalyst
directory. Requires some custom lines in .csproj
file.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论