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

chris

-----Original Message-----
From: mono-devel-list-boun...@lists.ximian.com 
[mailto:mono-devel-list-boun...@lists.ximian.com] On Behalf Of Edward Ned 
Harvey (mono)
Sent: Tuesday, March 29, 2016 5:49 AM
To: Greg Young <gregoryyou...@gmail.com>; Jason Curl <jcurln...@arcor.de>
Cc: mono-devel-list@lists.ximian.com
Subject: Re: [Mono-dev] Cross Platform on Linux/Windows with Mono.Posix 
reference on Linux

> From: mono-devel-list-boun...@lists.ximian.com 
> [mailto:mono-devel-list- boun...@lists.ximian.com] On Behalf Of Greg 
> Young
> 
> <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@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to