Where to specify preprocessor directives in visual studio?
You have two options:
-
Define it at the code file level. At the beginning of the file, write
#define FLAG
. You cannot place anything else (other than comments and blank lines) before directivesdefine
. As Ron Beyer points out, a directive defined in a file only exists for that file. -
Define it at the project level. Right click on the project in Solution Explorer, select Properties, then Build tab, then browse Compile Conditional Symbols. There are several characters separated by commas:
FLAG,FOO,BAR
. Note that this list of symbols depends on the project configuration (there is a config selector on the same tab).
And since EBrown will align define
doesn't work the same way in C # as it does in C. In C #, you just declare that the symbol exists, but you can't assign a value to it. Hence, the only use of these symbols is for directives #if FLAG
and for conditional attribute .
source to share