Say for instance I have a Visual Studio project with a configuration called "MyConfig" and I have the compilation symbol MY_CONFIG_SYMBOL
defined.
Is there a macro or command to see if MY_CONFIG_SYMBOL
is defined in the pre/post build events? Something like #if MY_CONFIG_SYMBOL
, but for the build event?
Right click the project (The Class Library is a project) and click Properties to open the properties window. Then click the Build tab, input symbols in the “Conditional compilation symbols:” textbox. Use comma to separate each symbol (e.g. “MySymbol1,MySymbol2”). Then use them in this way.
Conditional compilation is the ability to specify that a certain block of code will be compiled into the application only under certain conditions. Conditional compilation uses precompiler directives to affect which lines are included in the compilation process.
Conditional compilation provides a way of including or omitting selected lines of source code depending on the values of literals specified by the DEFINE directive. In this way, you can create multiple variants of the same program without the need to maintain separate source streams.
I finally found an answer. The following works perfectly:
if "$(DefineConstants.Contains('DEBUG'))" == "True" <command>
This works for any constants defined in the build, but note that the constant is case-sensitive ('DEBUG' != 'Debug').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With