monoxbuild

How to check Mono version at COMPILE time with xbuild, not Runtime


I know how to check at runtime, but that does no good for my current problem. I have an issue where a certain version of mono (Mono < 4.8.0) does not have TLS 1.1 nor 1.2 support and would not even compile, let alone run. So I need to add a #if to determine which version of mono is being used to compile with but I cant find anything that would do this. #if MONO is not sufficient. Another useful cheatsheet would be something that lists all of mono's predefined vars that are available to the compiler. I'm sure version would probably have been one of those items.

BTW, all users of this project would be compiling the app themselves, so there is no need to do runtime checking. If their mono doesnt support TLS 1.1/1.2, then it should still build on their machine, their particular binary just wouldnt have 1.1/1.2 in them which is completely fine since only they would be running it anyway.


Solution

  • You can export a env var. and use it to set a compiler directive:

    Example:

    export MONO_VERSION=`mono --version | grep version | cut -d " " -f 5`
    echo $MONO_VERSION
    5.10.0.179