Because C# doesn’t use define directives like other platforms you don’t get the same compile time options based on platform target etc. The simple solution is to set a “Conditional compilation symbol” as follows

In Project properties > Build

Select the platform you want to detect . In “Conditional compilation symbols”, add a new symbol name, e.g. “MY_SPECIAL_SYMBOL”, separating it from any others already there with a “;” is necessary.

Now select the alternative configuration “Debug / Release” and add it again.

Now you have a symbol you can use in code that will only be defined when that Platform is selected.

Then in code you can use:

#if MY_SPECIAL_SYMBOL

#endif

#if !MY_SPECIAL_SYMBOL

#endif
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *