开发者

Is developing in Mono cross-platform?

开发者 https://www.devze.com 2023-01-10 09:58 出处:网络
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)?

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

So what are the particularities of deve开发者_如何学编程loping with Mono? What are the advantages over developing with Visual Studio (except cross-platform thinghie)?


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

  • Strive to steer clear of Windows specific APIs
  • 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.
  • Do not use advanced GUI properties that may not be present in Mono.
  • 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 '\'.
  • 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.

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


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

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

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


Mono itself is cross platform.

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

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.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号