windows 在 Mono 中开发是否跨平台?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3429451/
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-15 14:59:30  来源:igfitidea点击:

Is developing in Mono cross-platform?

c#windowslinuxmono

提问by Andrei Zisu

In what measure is developing with mono cross-platform? How do I compile for Windows (in Linux), how do I run things in Linux (because there is no .NET JIT compiler)?

使用mono跨平台开发的措施是什么?如何为 Windows 编译(在 Linux 中),如何在 Linux 中运行(因为没有 .NET JIT 编译器)?

So what are the particularities of developing with Mono? What are the advantages over developing with Visual Studio (except cross-platform thinghie)?

那么使用 Mono 开发有什么特点呢?与使用 Visual Studio 开发相比有哪些优势(跨平台的东西除外)?

回答by t0mm13b

Developing in Mono is definitely cross-platform with a caveat emptor:

在 Mono 中开发绝对是跨平台的,但有一个警告

  • Strive to steer clear of Windows specific APIs
  • No interoperability with the native Windows APIs... or... you can #ifdefout the Windows API and provide your own Mono wrapper in order to minimize code changes, for example, there's a DLL wrapper that uses Interop to invoke a Win32 method such as 'GetFont', this is a hypothetical example, GetFont will return the Font information, under Mono, that does not exist but however you can create a fake wrapper that returns nothing and incorporate the #ifdefmacro to use the wrapper when compiling under Mono, and switch off the macro when compiling under Windows, how you implement the wrapper is up to you.
  • Do not use advanced GUI properties that may not be present in Mono.
  • Use the Environment property such as NewLineto make it independant of Unix's CR and Win32's CRLF, same apply for Path Separator, for Unix '/' and for Win32 '\'.
  • Serialization is slightly different under Mono, you serialize an object on Mono, do not kid yourself into thinking it will be de-serialized under Win32 and vice versa.
  • 努力避开 Windows 特定的 API
  • 没有与本机 Windows API 的互操作性……或者……您可以#ifdef退出 Windows API 并提供您自己的 Mono 包装器以最大限度地减少代码更改,例如,有一个 DLL 包装器使用 Interop 来调用 Win32 方法,例如'GetFont',这是一个假设的例子,GetFont 将返回 Mono 下不存在的字体信息,但是您可以创建一个不返回任何内容的假包装器,并#ifdef在 Mono 下编译时合并宏以使用包装器,然后切换在 Windows 下编译时关闭宏,如何实现包装器取决于您。
  • 不要使用 Mono 中可能不存在的高级 GUI 属性。
  • 使用 Environment 属性NewLine使其独立于 Unix 的 CR 和 Win32 的 CRLF,同样适用于路径分隔符、Unix '/' 和 Win32 '\'。
  • Mono 下的序列化略有不同,您在 Mono 上序列化一个对象,不要自欺欺人地认为它会在 Win32 下反序列化,反之亦然。

Lastly but not least, keep checking from Mono to Win32 and back again, keep testing and testing it.

最后但并非最不重要的是,不断检查从 Mono 到 Win32,然后再返回,继续测试和测试它。

回答by Oded

Much of the mono runtime is compatible with the CLR, as they follow the same standard.

大部分单声道运行时都与 CLR 兼容,因为它们遵循相同的标准。

This means that once you compile your code (in Mono orvisual studio), so long as you make sure to only use features supported by both (for example no WMI stuff in mono) and write your application to be platform aware, using best practices (examples are using Path.Combineto build file and directory paths, using Environment.NewLinefor outputting new lines and more), your application can run unmodified on any platform that has either Mono or the CLR (this includes Windows, Linux and Mac).

这意味着一旦你编译了你的代码(在 MonoVisual Studio 中),只要你确保只使用两者都支持的特性(例如,mono 中没有 WMI 的东西)并使用最佳实践编写你的应用程序以了解平台(示例Path.Combine用于构建文件和目录路径,Environment.NewLine用于输出新行等),您的应用程序可以在具有 Mono 或 CLR(包括 Windows、Linux 和 Mac)的任何平台上未经修改地运行。

You can develop with mono in visual studio, so the part of your question regarding that is moot.

您可以在 Visual Studio 中使用单声道进行开发,因此您的问题的一部分是没有实际意义的。

回答by Alan

Mono itself is cross platform.

Mono 本身是跨平台的。

By developing with mono specifically, you will be able to run your executable on any platform that has mono available for it. That in and of itself is mono's biggest advantage over developing on MSFT's .Net platform. Said differently: If you build you assembly with mono, you're guarantee cross-platform support, where as building with .Net may not give you that.

通过专门使用单声道进行开发,您将能够在任何具有单声道可用的平台上运行您的可执行文件。这本身就是 Mono 相对于在 MSFT 的 .Net 平台上开发的最大优势。换种说法如果您使用单声道构建程序集,则可以保证跨平台支持,而使用 .Net 构建可能无法为您提供支持。

Mono has made some upgrades to deficiencies in .Net (for example Mono.security offered features not found in .Net 2.0, though I believe MSFT picked them up for later releases).

Mono 对 .Net 中的缺陷进行了一些升级(例如 Mono.security 提供了 .Net 2.0 中没有的功能,但我相信 MSFT 为以后的版本选择了它们)。

It is possible to build a .Net Assembly using Visual Studio, and have Mono run it on, however your assembly must take care to use only the frameworks/libraries that Mono supports, and that any unmanaged assemblies referenced by your assembly are available for your chosen OS. In otherwords: if your assembly makes use of a C++ dll on windows, you must ensure you have the correct .a/.so file for linux.

可以使用 Visual Studio 构建 .Net 程序集,并让 Mono 在其上运行它,但是您的程序集必须注意仅使用Mono 支持的框架/库,并且您的程序集引用的任何非托管程序集都可用于您的程序集。选择的操作系统。换句话说:如果你的程序集在 Windows 上使用 C++ dll,你必须确保你有正确的 .a/.so 文件用于 linux。

To run your .net assembly in Linux (assuming mono is installed properly) you type: mono myprogram.exe

要在 Linux 中运行您的 .net 程序集(假设 mono 已正确安装),请键入: mono myprogram.exe

回答by Benny Skogberg

The only advantage developing on Mono is that you can use a Mac OS X or Linux environment. But if you have a choice, never leave Visual Studio. To the best of my knowledge,Visual Studio is the best IDE available for development in C# and VB.

在 Mono 上开发的唯一优势是您可以使用 Mac OS X 或 Linux 环境。但是,如果您有选择,请永远不要离开 Visual Studio。据我所知,Visual Studio 是可用于 C# 和 VB 开发的最佳 IDE。