您可以在 Mac 上安装和运行基于 .NET 框架构建的应用程序吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31864724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:42:30  来源:igfitidea点击:

Can you install and run apps built on the .NET framework on a Mac?

.netmacos

提问by adz

I need to use/continue developing a desktop app developed using .NET on my Mac. Is there a .NET framework 4.0 available for Mac? Would this allow running and developing of .NET-based apps on a Mac?

我需要在 Mac 上使用/继续开发使用 .NET 开发的桌面应用程序。是否有适用于 Mac 的 .NET Framework 4.0?这是否允许在 Mac 上运行和开发基于 .NET 的应用程序?

Another option that i am considering is using a windows virtual machine on the Mac.

我正在考虑的另一个选择是在 Mac 上使用 Windows 虚拟机。

采纳答案by Mehdi Laribi

(Updating this post to clarify the situation and difference between .Net Framework and .Net Core - October 2019)

(更新这篇文章以澄清 .Net Framework 和 .Net Core 之间的情况和区别 - 2019 年 10 月)

The devil is in the detail here:

魔鬼在细节中:

  • As the .Net Frameworkis not available on Mac or Linux operating systems, you cannot take a compiled application that targets the .Net Framework try to get it to run on Mac OS.

  • Installing the Mono Project runtime (https://www.mono-project.com) allows you to re-compile the code and run it on a Mac, but this requires various alterations to the codebase, as the fuller .Net Framework is not available. (Also, WPF applications aren't supported here either.)

  • However, applications written which target .Net Corewill work on Windows, Mac OS and Linux, as the .Net Core runtime is available. (https://dotnet.microsoft.com/)
  • 由于.Net Framework在 Mac 或 Linux 操作系统上不可用,因此您不能将针对 .Net Framework 的已编译应用程序尝试让它在 Mac OS 上运行。

  • 安装 Mono Project 运行时 ( https://www.mono-project.com) 允许您重新编译代码并在 Mac 上运行它,但这需要对代码库进行各种更改,因为更完整的 .Net Framework 不是可用的。(此外,此处也不支持 WPF 应用程序。)

  • 但是,由于 .Net Core 运行时可用,因此针对.Net Core编写的应用程序可以在 Windows、Mac OS 和 Linux 上运行。( https://dotnet.microsoft.com/)

Workarounds to this might be:

解决方法可能是:

  1. Update the original code for the application and target .Net Core and recompile it, meaning you end-up with a .Net Core application, which will work in multiple environments with the same codebase.

  2. Create a branch of the original code and recompile to run targeting the Mono Project framework. Downside to this, is that you then have a second branch of code to maintain alongside the original, meaning more work longer term.

  3. Install a Virtual Machine running Windows on your Mac. (Parallels might help hide away the fact that it's actually running on a Windows PC VM.) This essentially removes the problem, but introduces more in other ways, such as another VM on your network to maintain.

  1. 更新应用程序的原始代码并以 .Net Core 为目标并重新编译它,这意味着您最终会得到一个 .Net Core 应用程序,它将在具有相同代码库的多个环境中工作。

  2. 创建原始代码的一个分支并重新编译以针对 Mono 项目框架运行。这样做的缺点是,您将有第二个代码分支与原始代码一起维护,这意味着更多的工作更长期。

  3. 在 Mac 上安装运行 Windows 的虚拟机。(Parallels 可能有助于隐藏它实际上是在 Windows PC VM 上运行的事实。)这基本上消除了问题,但在其他方面引入了更多问题,例如在您的网络上维护另一个 VM。

My thoughts:

我的想法:

Compiling an application to work on Mono (and therefore creating a different code 'branch' for this operating system) almost seems like a sideways step nowadays, as recompiling the code to work using .Net Core is a much more sustainable solution; the same code-base but compiled to target .Net Core is then compatible on Windows, Mac and Linux operating systems.

编译一个应用程序以在 Mono 上工作(因此为这个操作系统创建一个不同的代码“分支”)现在几乎似乎是一个横向的步骤,因为使用 .Net Core 重新编译代码是一个更可持续的解决方案;相同的代码库但编译为目标 .Net Core 然后兼容 Windows、Mac 和 Linux 操作系统。

回答by Sam Axe

  • .NET Corewill install and run on macOS - and just about any other desktop OS.
    IDEs are available for the mac, including:

  • Monois a good option that I've used in the past. But with Core 3.0 out now I would go that route.

回答by Goldorak84

Yes you can!

是的你可以!

As of November 2016, Microsoft now has integrated .NET Core in it's official .NET Site

截至 2016 年 11 月,Microsoft 现在已在其官方 .NET 站点中集成了 .NET Core

They even have a new Visual Studio appthat runs on MacOS

他们甚至有一个在MacOS上运行的新Visual Studio 应用程序

回答by Hasnain Hayder

.NetCore is a fine release from Microsoft and Visual Studio's latest version is also available for mac but there is still some limitation. Like for creating GUI based application on .net core you have to write code manually for everything. Like in older version of VS we just drag and drop the things and magic happens. But in VS latest version for mac every code has to be written manually. However you can make web application and console application easily on VS for mac.

.NetCore 是 Microsoft 的一个很好的版本,Visual Studio 的最新版本也可用于 mac,但仍有一些限制。就像在 .net core 上创建基于 GUI 的应用程序一样,您必须为所有内容手动编写代码。就像在旧版本的 VS 中一样,我们只需拖放事物,魔法就会发生。但是在 VS 最新版本的 mac 中,每个代码都必须手动编写。但是,您可以在 VS for mac 上轻松制作 Web 应用程序和控制台应用程序。