#if DEBUG doesn't seem to work in my VS 2010

.net, c#, debugging, visual-studio-2010

Solution

When using the 'Debug' configuration, you have to go to project's Properties -> Build and tick the 'Define DEBUG constant' box.

Either that, or define the conditional compilation symbol: DEBUG. As you can do with any other custom compilation symbol :)

Problem

I've been doing the following in my C# code: ``` #if DEBUG //Debugger only code #endif ``` But for some reason when I do the same in my C# console application (that is built as a Windows service in VS 2010) it doesn't seem to work and for both Release and Debug configurations it looks like `DEBUG` is not defined. Do I need to set something for that preprocessor constant to work?

Original source