[Mono-dev] Cross Platform on Linux/Windows with Mono.Posix reference on Linux
cswiedler at trionworlds.com
Tue Mar 29 15:58:37 UTC 2016
Why not just include references to Mono.Posix.dll in the Windows build? You don't have to install the full framework. We have a similar issue with server apps that are developed on Windows and run on Linux. We just put a win32 build of Mono into our source tree and added Mono.Posix as a reference. Everywhere we invoke any Posix code, we just wrap the statements in something like "if (Environment.OSVersion.Platform == PlatformID.Unix)".
From: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Edward Ned Harvey (mono)
Sent: Tuesday, March 29, 2016 5:49 AM
To: Greg Young <gregoryyoung1 at gmail.com>; Jason Curl <jcurlnews at arcor.de>
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] Cross Platform on Linux/Windows with Mono.Posix reference on Linux
> From: mono-devel-list-bounces at lists.ximian.com
> [mailto:mono-devel-list- bounces at lists.ximian.com] On Behalf Of Greg
> <Reference Include="Mono.Posix" Condition=" '$(OS)' != 'Windows_NT' "
(for clarification of my previous response, because I was asked for clarification off-list)
If you have some code that calls Mono.Posix.Something(), and you have a conditional reference to Mono.Posix in the project, then you're able to build on Mono, but on windows, without the reference, your call to Mono.Posix.Something() will not compile, which prevents you from building, even though at runtime you might never make that call. In order to compile on windows, you'll need to comment-out your Mono.Posix.Something() line, via #if or [Conditional], which means you need a compiler symbol to indicate whether you're building on mono or windows. This could be either separate project files, or multiple build configurations. (Or dynamically generated project files).
Maybe you can have a conditional reference to Mono.Posix on mono, and have a separate conditional reference to ../../ExtraClassLibraries/Mono.Posix.dll on windows, with copy-to-destination, so you can get the same code to build on both mono and windows, resulting in an effectively identical cross-platform binary... But I'm almost certain I recall somebody on this list telling me, that the JIT compiler can or will or might in the future, eagerly link assemblies at runtime (or just before runtime), so the Mono.Posix.dll file must be present on windows at runtime in order to avoid runtime exceptions, even though the runtime code execution will never execute that path.
You avoid all these problems by abstracting the functionality you want into an interface or abstract class, and using a factory to perform a runtime dynamic load of a mono-specific or windows-specific assembly with a derivative class. You can build the mono-specific assembly on mono, or maybe you can use the double-conditional described above and get the mono-specific assembly to also be buildable on windows. No need to copy Mono.Posix.dll to the destination, because Mono.Posix will only be called at runtime when run on mono.
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
More information about the Mono-devel-list