在Mono跨平台开发吗?

时间:2022-01-26 02:14:28

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)?

那么单声道发展的特殊性是什么呢?与使用Visual Studio(除了跨平台thinghie)开发相比,使用Visual Studio有什么优势?

4 个解决方案

#1


28  

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

在Mono中开发绝对是跨平台的,但需要注意的是:

  • Strive to steer clear of Windows specific APIs
  • 尽量避免使用Windows特定的api
  • No interoperability with the native Windows APIs... or... you can #ifdef out 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 #ifdef macro 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.
  • 没有与本机Windows api的互操作性……还是……# ifdef Windows API,可以提供自己的Mono包装为了最小化代码更改,例如,有一个调用一个Win32 DLL封装器,利用互操作方法如“GetFont”,这是一个假设的例子,GetFont将返回的字体信息,在Mono,然而这并不存在,但您可以创建一个假的包装器,它返回,将# ifdef宏时使用包装器在Mono下编译,在Windows下编译时关闭宏,如何实现包装由您决定。
  • Do not use advanced GUI properties that may not be present in Mono.
  • 不要使用可能不存在于Mono中的高级GUI属性。
  • Use the Environment property such as NewLine to make it independant of Unix's CR and Win32's CRLF, same apply for Path Separator, for Unix '/' and for Win32 '\'.
  • 使用环境属性,如NewLine,使其与Unix的CR和Win32的CRLF无关,同样适用于路径分隔符,适用于Unix' /'和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.
  • 在Mono下序列化略有不同,您在Mono上序列化一个对象,不要自欺欺人地认为它将在Win32下反序列化,反之亦然。

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

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

#2


3  

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

许多mono运行时都与CLR兼容,因为它们遵循相同的标准。

This means that once you compile your code (in Mono or visual 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.Combine to build file and directory paths, using Environment.NewLine for 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).

这意味着,一旦您编译代码(在Mono或visual studio中),只要您确保只使用两者支持的特性(例如,在Mono中没有WMI内容),并使用最佳实践(示例是使用Path)将应用程序编写为平台敏感的。结合使用环境构建文件和目录路径。你的应用程序可以在任何有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中使用mono进行开发,因此您的问题的一部分是没有意义的。

#3


2  

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进行开发,您将能够在任何有mono可用的平台上运行您的可执行文件。这本身就是mono在MSFT的。net平台上开发的最大优势。换句话说:如果你用mono构建你的程序集,你就保证了跨平台的支持,而使用。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)。安全性提供了。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/。所以文件为linux。

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

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

#4


1  

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。

#1


28  

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

在Mono中开发绝对是跨平台的,但需要注意的是:

  • Strive to steer clear of Windows specific APIs
  • 尽量避免使用Windows特定的api
  • No interoperability with the native Windows APIs... or... you can #ifdef out 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 #ifdef macro 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.
  • 没有与本机Windows api的互操作性……还是……# ifdef Windows API,可以提供自己的Mono包装为了最小化代码更改,例如,有一个调用一个Win32 DLL封装器,利用互操作方法如“GetFont”,这是一个假设的例子,GetFont将返回的字体信息,在Mono,然而这并不存在,但您可以创建一个假的包装器,它返回,将# ifdef宏时使用包装器在Mono下编译,在Windows下编译时关闭宏,如何实现包装由您决定。
  • Do not use advanced GUI properties that may not be present in Mono.
  • 不要使用可能不存在于Mono中的高级GUI属性。
  • Use the Environment property such as NewLine to make it independant of Unix's CR and Win32's CRLF, same apply for Path Separator, for Unix '/' and for Win32 '\'.
  • 使用环境属性,如NewLine,使其与Unix的CR和Win32的CRLF无关,同样适用于路径分隔符,适用于Unix' /'和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.
  • 在Mono下序列化略有不同,您在Mono上序列化一个对象,不要自欺欺人地认为它将在Win32下反序列化,反之亦然。

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

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

#2


3  

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

许多mono运行时都与CLR兼容,因为它们遵循相同的标准。

This means that once you compile your code (in Mono or visual 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.Combine to build file and directory paths, using Environment.NewLine for 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).

这意味着,一旦您编译代码(在Mono或visual studio中),只要您确保只使用两者支持的特性(例如,在Mono中没有WMI内容),并使用最佳实践(示例是使用Path)将应用程序编写为平台敏感的。结合使用环境构建文件和目录路径。你的应用程序可以在任何有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中使用mono进行开发,因此您的问题的一部分是没有意义的。

#3


2  

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进行开发,您将能够在任何有mono可用的平台上运行您的可执行文件。这本身就是mono在MSFT的。net平台上开发的最大优势。换句话说:如果你用mono构建你的程序集,你就保证了跨平台的支持,而使用。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)。安全性提供了。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/。所以文件为linux。

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

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

#4


1  

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。