Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use conditional compilation symbols in VS build events?

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?

like image 272
Mike Webb Avatar asked Aug 30 '12 15:08

Mike Webb


People also ask

How do you use conditional compilation symbols in C#?

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.

What is conditional compilation in VB net?

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.

What is meant by conditional compilation?

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.


1 Answers

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').

like image 190
Mike Webb Avatar answered Sep 27 '22 23:09

Mike Webb