tags:

views:

590

answers:

2

I need a conditional compilation switch that knows if I am compiling for the mono or MS .NET runtime. How can I do this?

+11  A: 

The Mono compiler defines __MonoCS__

BUT, BUT, BUT, the whole point of Mono is that you can take an assembly that you built with VS and run it on Mono, or vice versa.

It seems to me that if you need to have Mono vs MS.NET differences, then you need to be making those decisions at run-time.

The standard way to detect Mono at Runtime is:

bool runningOnMono = Type.GetType ("Mono.Runtime") != null;
Will Dean
Understand the point but Mono has a lot of catching up to do in places, and there is no point penalising the MS build...Good tip though thanks
Frep D-Oronge
JOOI, what particular gaps in Mono are you working around?
Will Dean
+1  A: 

@Will Dean

You occasionally need to use conditionally compilations. E.g. Mono doesn't support the attribute; ViewStateModeById which triggers a runtime failure if you've tagged a class with it. So what you're saying is not completely accurate...

Thomas Hansen
I'm not familiar with that attribute, but that still seems to me that the future presence or absence of the ViewStateModeById attribute is not something which *directly* correlates with the compiler which was used to compile your assemblies. But there's always __MonoCS__ if it does...
Will Dean
@WillIt will trigger a runtime failure when trying to load the assembly... :(But in general terms I agree with you, though it's not always possible...
Thomas Hansen