[Mono-list] Making code conditional on "not running on mono"?

Miguel de Icaza miguel@ximian.com
18 May 2003 17:08:39 -0400


Hello,

> > We do somthing similar in nant. Except we use #ifdef mono.
> > Another way to test if you are on windows it to check the value of 
> > DirectorySeperatorchar. That won't help if you're trying to test for 
> > mono since you cold be on mono on wondows.
> 
> Hey cool, I didn't know that C# had a preprocessor :)
> 
> Question to the Mono developers: Would it be worth making "/d:mono" or 
> "/d:mcs" a default in mcs? That would make it possible to write code 
> that compiles differently on Mono without having to specialcase your 
> build scripts.
> 
> (this seems analagous to the fact that you can assume things like 
> "#ifdef linux" and "#ifdef gcc" in C and get meaningful results without 
> having to explicitly -D them on the commandline)

Although we do have such define (__MonoCS__ as pointed out in the
thread elsewhere), its use is highly discouraged.

It can be used to workaround bugs in the Mono C# compiler, but should
not be used as a portability tool.  In principle your code should
dynamically determine the host OS and deal with it appropriately.

If you are willing to have two separate builds (one for Windows, and
one for Mono).  The __MonoCS__ is not the right tool to use either,
because this only flags whether the compiler being used is the Mono
one, not what platform the code is targeting.

Miguel.