Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to specify preprocessor directives in visual studio?

Trying to define a preprocessor directives in the Visual studio 2012.

#define FLAG
....
#endif

But not sure, where to include this FLAG in visual studio - C#. I remember specifying something like this in C++ projects.

Any thoughts ?

like image 925
now he who must not be named. Avatar asked May 20 '15 13:05

now he who must not be named.


1 Answers

You have two options as to where to define it:

  1. Code file level - In the beginning of the file write #define FLAG. You cannot place anything else (other than comments and blank lines) before define directives. As Ron Beyer points out, a directive defined in a file exists only for that file.

  2. Project level - Right click in the project in Solution Explorer, select Properties, then the Build tab, then look at Conditional compilation symbols. Then one can define several comma-separated symbols there such as: FLAG,FOO,BAR. Note that this symbols list is project configuration dependent (there is a configuration selector in the same tab).


Note as mentioned in the comments, define does not work in C# the same way that 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 for these symbols is for #if FLAG directives and for the Conditional attribute.

like image 70
Konamiman Avatar answered Oct 06 '22 04:10

Konamiman