Is there a #if LINUX?

When I run the following code on Linux Mint (18.1 Cinnamon 64-bit, v 3.2.7) the output is ELSE:

#if LINUX
  Console.WriteLine("LINUX");
#else
  Console.WriteLine("ELSE");
#endif

What am I missing?

Where are these directives defined so I can look at all of them? (I cloned the MonoGame repository and did a grep [grep -rnw ./ -e ‘IOS’] but still don’t see where that’s defined).

MonoGame defines don’t carry over to your own project. If you want to use preprocessor directives you need to define them yourself. There’s no magic for these things.

If this is about modifying MG source you can see the relevant defines in the Protobuild .definition files. E.g. https://github.com/MonoGame/MonoGame/blob/develop/Build/Projects/MonoGame.Framework.definition for the MG runtime. Note that some services may add or remove defines for certain platforms. LINUX is defined for Linux, but that could get removed soon because the only runtime for Linux is the cross platform desktop one which should work the same across desktop platforms (obviously). So it can’t have platform specific code thus it doesn’t need platform specific defines (in fact it’s safer to not have them).

But would the OP not need to know the Platform in order for code that is unrelated to all platforms to be ignored in compilation?

That and UI specific commands…

Well, like I said, if you want to use preprocessor #if statements you need to define the symbols yourself. MG can’t do that for you because defined symbols from libraries you reference don’t carry over. I’m not sure if the templates MG provides define any symbols, but that could be done.

1 Like