Mono: Mono portability across Windows and Linux clarification

Created on 25 Aug 2020  路  3Comments  路  Source: mono/mono

I would like to clarify something I read here: https://www.mono-project.com/docs/getting-started/application-portability/#developing-on-windows-running-on-unix

It mentions You can continue to use Visual Studio to develop your applications on Windows, the binaries produced by Visual Studio are binary compatible with Mono, so you only need to get these files to your Linux/Unix server.

Does this apply to a specific version of Mono and upwards and won't be the case with earlier versions of Mono? What is the correct and standard practice of building .NET applications that run cross different operating systems?

For example should the application be compiled under Linux if it is intended to run in Linux or can the application be compiled in Windows or Linux and it would work fine in either OS? According to the statement this isn't the case but just need someone to clarify this because according to some SO answers the binaries aren't always compatible: https://stackoverflow.com/questions/63570298 therefore would it be safer just to build in the environment it is intended to run in?

A specific example is we have an F# application that is intended to run under Mono in Linux, we currently compile the application in a Mono docker container. Instead could we use msbuild on Windows to reduce the need of the docker container and expect that it will work correctly? Again what is the standard practice here?

Secondly what is the guidance on compiling applications in specific versions of Mono and running them on different runtimes? Should the version of Mono that the application was built in match the runtime version? Will an application built in a version older than the runtime work correctly? Is there any backward compatibility across Mono versions?

Many thanks

question

All 3 comments

This applies specifically to managed code compiled for "Any CPU" https://stackoverflow.com/questions/516730/what-does-the-visual-studio-any-cpu-target-mean

If your code doesn't do anything platform-specific, like pinvoking .dlls that don't have a .so equivalent, or using \ in paths, it should work fine on any platform regardless of which platform is used to build it.

I don't know about F# specifically, but I don't have any reason to believe the output from msbuild would behave differently.

For example should the application be compiled under Linux if it is intended to run in Linux or can the application be compiled in Windows or Linux and it would work fine in either OS

This is not required. You can compile on different OS/architecture if you are compiling managed code (e.g. C#/F#) only. Though your code needs to be written to be cross-platform to actually work (e.g. no hardcoding of c:\ ).

If your project also has native dependencies you need to deal with them as platform-specific and compile them for the target platform.

Secondly what is the guidance on compiling applications in specific versions of Mono and running them on different runtimes?

Mono includes multiple .NET Framework APIs (e.g. .NET 4.7.1 API). Compiling against them, which is the default mode for msbuild, ensures that the output will run on any Mono or .NET version which supports the API level. This way you can even compile using .NET Framework toolchain on Windows and copy the output and run it with Mono on Linux.

Just wanted to say thanks @marek-safar and @madewokherd for the detailed explanations.

Was this page helpful?
0 / 5 - 0 ratings