[Mono-dev] Mono.Posix Cross Compiling

Edward Ned Harvey (mono) edward.harvey.mono at clevertrove.com
Tue Jan 6 16:12:03 UTC 2015

> From: Dave Curylo [mailto:dacurylo at gmail.com] On Behalf Of David Curylo
> You have to use conditional compilation for the code that uses the
> conditional reference, in this case Mono.Posix.  The reference appears with a
> warning in Visual Studio and you get a compiler warning, "The referenced
> component 'Mono.Posix' could not be found" but this is to be expected on
> Windows/.NET.  This may be an annoyance, but it allows developers to be
> productive developers on either platform, so I consider this to be a functional
> solution.
> I created an example here on github:
> https://github.com/ninjarobot/MonoConditionalReference
> This builds fine on Xamarin Studio on OS X and Visual Studio on Windows,
> although given the conditional compilation, the resulting assembly is
> different.  We take this approach in my organization so that some developers
> can work on Windows with Visual Studio and other developers work entirely
> on mono (our target platform).

That's cool, but - You don't need to add the "Conditional" clause to the <Reference> tag of the csproj.  I just checked out your project, and got rid of the conditional clause in the csproj, so the reference to Mono.Posix is unconditional.  The behavior is the same.  It compiles fine and gives warning about the unused and broken reference.  The reason it works is because of the #if __MonoCS__ which eliminates any calls to the missing assembly.

As long as you can eliminate any calls to the missing assembly via #if or [Conditional], then you don't actually need the assembly and it's ok to ignore the warning about broken reference, missing assembly.

The time when a real problem occurs is when you actually *do* need the assembly.  For example, if I copy Mono.Security.dll over to windows, and create a project that uses it in both windows & mono, then I have something like this in the windows csproj:

    <Reference Include="Mono.Security">

Which will not compile on mono.  So in mono, I have to modify the csproj to be like this:

    <Reference Include="Mono.Security" />

Which will not compile on Windows.

As far as I can tell, any attempt to use Conditional property in the <Reference> tag is simply ignored.  So I settle on using the kludgy hack of using different csproj files on windows & mono.  It works so I didn't spend more time on it - but if there's a more elegant solution, I'd like to know.

More information about the Mono-devel-list mailing list