I have a C# application that I am building with Visual Studio 2010. To help me with some of my routine tasks in the app, I wanted to set some values if I compiled the app in debug mode. Naturally, I though preprocessor directives would be a good idea. My problem is, I don’t quite understand how to use them. At this time, I have a block of code that looks like this:
#define DEBUG
... // Other code in my app
#if DEBUG
myVariable = debugValue;
#endif
My problem is, when I compile my app in release mode, myVariable still gets set to debugValue. It’s like I’m not properly defining my preprocessor variable or I’m not configuring my compiler correctly. Can anybody explain to me what I need to do so that myVariable is only set to debugValue when I compile the app in debug mode?
Thank you!
If you are using
#define DEBUGto specify the debug symbol, switching to release mode will still provide the symbol, since you are explicitly defining it.Try removing the
#define DEBUGline in your code files. By default VS definesDEBUGandTRACEin debug mode andTRACEin release mode, so its not necessary to explicitly define them.