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
2008-11-30 17:04:37
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
2008-12-02 11:18:07
JOOI, what particular gaps in Mono are you working around?
Will Dean
2008-12-02 19:38:43
+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
2008-11-30 17:15:31
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
2008-11-30 18:07:24
@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
2008-11-30 18:46:50