[Mono-dev] Cross Platform on Linux/Windows with Mono.Posix reference on Linux

Jason Curl jcurlnews at arcor.de
Thu Apr 7 09:29:34 UTC 2016


On 07/04/2016 08:06, Greg Young wrote:
> "I thought Greg's reply would be useful to tell MonoDevelop on Linux
> not to even reference the nuget package, but I didn't get that
> working."
>
> Mine was for VS / msbuild / xbuild. I don't know about MonoDevelop.

Thanks Greg. MonoDevelop still wanted to download the Mono.Posix.dll in 
any case even after I took your hints.
>
> On Wed, Apr 6, 2016 at 9:01 PM, Jason Curl <jcurlnews at arcor.de> wrote:
>> Thanks all for your ideas.
>>
>> My project (github.com/jcurl/serialportstream) ended up including Mono.Posix
>> via nuget to allow it to compile on Windows. I found an option that doesn't
>> copy the assembly to the target path. I thought Greg's reply would be useful
>> to tell MonoDevelop on Linux not to even reference the nuget package, but I
>> didn't get that working. The IDE would still parse the entries and download
>> from NuGet. So i assume when I compile on Linux, it's linking against the
>> nuget version and not the OS version, but when running, it must be using the
>> OS version and the library isn't copied to the destination.
>>
>> I had already implemented a factory OO model, which I use to instantiate
>> either WinNativeSerial or UnixNativeSerial on knowing the environment
>> platform ID that's in use.
>>
>> If "the JIT compiler can or will or might in the future, eagerly link
>> assemblies at runtime" were sometime to become true, then I've got a problem
>> - I certainly don't want to distribute Mono.Posix.
>>
>> Could I expect problems when compiling against a different version (nuget)
>> that is being used at run-time (os)?
>>
>> Thankyou!
>>
>>
>> On 29/03/2016 17:58, Chris Swiedler wrote:
>>> 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-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
>>>> 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 at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>
>
>



More information about the Mono-devel-list mailing list