简体   繁体   English

编译基于 C# 的 Windows (WinForms App) 应用程序以在 Mac OS High Sierra 或 Mojave 上运行

[英]Compile C# based Windows (WinForms App) application to run on Mac OS High Sierra or Mojave

I have built an (Windows Forms App) application on Windows in C#.我在 Windows 上用 C# 构建了一个(Windows 窗体应用程序)应用程序。 Now, I would like to target this whole project / application to mac OS without changing the application.现在,我想在不更改应用程序的情况下将整个项目/应用程序定位到 mac OS。 Is there any easy way to achieve it?有什么简单的方法可以实现吗? I don't want to rebuild the entire app from scratch on MAC.我不想在 MAC 上从头开始重建整个应用程序。 I don't want to use virtual machine on MAC... I have Visual Stuido 2017 and a paired MAC.我不想在 MAC 上使用虚拟机...我有 Visual Stuido 2017 和配对的 MAC。 But, I'm lost here.但是,我在这里迷路了。

;TLDR Mono , using WinForms and MonoDevelop IDE for development. ;TLDR Mono ,使用WinFormsMonoDevelop IDE 进行开发。

.NET Framework is the full implementation that includes everything but runs only on Windows. .NET Framework是完整的实现,包括所有内容,但只能在 Windows 上运行。

.NET Core is the newer OpenSource implementation of .Net framework but doesn't include WPF/WinForms - because those rely heavily on DirectX/GDI essentially making them Windows only. .NET Core是 .Net 框架的较新的开源实现,但不包括 WPF/WinForms - 因为它们严重依赖 DirectX/GDI,本质上使它们仅适用于 Windows。

Xamarin .哈马林 Xamarin based off of Mono framework branched more towards iOS and Android.基于 Mono 框架的 Xamarin 分支更多地面向 iOS 和 Android。 There is a Xamarin Mac but it supports the same GTK# based UI toolkit as Mono.There is a WinForms equivalent UI toolkit as well called Xamarin Forms but it is mobile only (iOS, Android & Universal Windows Platform)有一个 Xamarin Mac,但它支持与 Mono 相同的基于 GTK# 的 UI 工具包。有一个 WinForms 等效的 UI 工具包,也称为Xamarin Forms,但它仅适用于移动设备(iOS、Android 和通用 Windows 平台)

Mono .单声道 Mono is OpenSource implementation of .Net framework, uses GTK# by default for UI. Mono 是 .Net 框架的开源实现,默认使用 GTK# 作为 UI。 Does run fine on all of Windows, Linux, macOS.在所有 Windows、Linux、macOS 上运行良好。 Uses GTK# as underlying UI toolkit on all OSes including Windows.在包括 Windows 在内的所有操作系统上使用 GTK# 作为底层 UI 工具包。

What's Cross Platform?什么是跨平台? There is a subset of Base Class Library, called .NET Standard Library - as well as the compilers platform, only these subsets of .Net are truly cross-platform.有一个基类库的子集,称为.NET 标准库- 以及编译器平台,只有 .Net 的这些子集才是真正的跨平台。

To sum it up, Mono does however support Windows Forms on both Linux & macOS.总而言之,Mono 确实支持 Linux 和 macOS 上的Windows 窗体 Except some corner cases it works very well.除了一些极端情况,它工作得很好。 However the UI look and feel is Windows only.但是,UI 外观和感觉仅适用于 Windows。 It is like running Windows applications under WINE.这就像在 WINE 下运行 Windows 应用程序。 Default Mono IDE is MonoDevelop .默认 Mono IDE 是MonoDevelop

Xamarin Mac is great if you want to write a new application from scratch since Xamarin Mac exposes you full macOS SDK and offers its own IDE (Xamarin Studio).如果您想从头开始编写新应用程序, Xamarin Mac非常棒,因为 Xamarin Mac 向您公开了完整的 macOS SDK 并提供了自己的 IDE (Xamarin Studio)。

In your situation though, Mono is best option.不过,在您的情况下,Mono 是最佳选择。 After having installed mono you can even try running your current app as mono appName from terminal.安装 mono 后,您甚至可以尝试从终端以mono appName运行您当前的应用程序。 It should render the UI even if the paths and other resources are broken.即使路径和其他资源被破坏,它也应该呈现 UI。

Update 2021 2021 年更新

WPF and WinForms now are open source and part of .Net Core (which now is referred to as .Net . Core is dropped in name). WPF 和 WinForms 现在是开源的并且是 .Net Core 的一部分(现在被称为.Net 。Core 已在名称中删除)。 The previous classic .Net is now called .Net framework.以前的经典 .Net 现在称为 .Net 框架。 New WPF/WinForms features enhancements are on available for .Net only.新的 WPF/WinForms 功能增强仅适用于 .Net。 Though these still are Windows only and will stay so.尽管这些仍然只是 Windows 并且将保持如此。

Avalonia UI Framework and Uno Platform are newer .Net Core (AKA .Net) based cross-platform solutions. Avalonia UI 框架Uno 平台是较新的基于 .Net Core (AKA .Net) 的跨平台解决方案。 Both use XAML.两者都使用 XAML。 Avalonia is more like WPF while Uno tries to be cross-platform UWP. Avalonia 更像是 WPF,而 Uno 则试图成为跨平台的 UWP。

You have to use .NET Core (not .NET Framework) to run app properly on different OS than Windows.您必须使用 .NET Core(而不是 .NET Framework)才能在与 Windows 不同的操作系统上正确运行应用程序。

Differences between platforms explained 平台之间的差异解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM