Brian Mains
Brian Mains

Reputation: 50728

#if DEBUG Always True for DEBUG and RELEASE modes

For some reason, Any code like:

#if DEBUG
    CallSomeMethod();
#endif

Is always true regardless of debug or release mode. Any ideas why, and what setting I can use to turn the feature on or off? For the project, define DEBUG constant is set to true.

Thanks.

Upvotes: 10

Views: 6250

Answers (6)

Nikhil Vasani
Nikhil Vasani

Reputation: 11

I had kept the "Define DEBUG Constant" unchecked in Release configuration. Still, when I ran the Application after publishing it, it was running in Debug mode.

Because I when I published the application, 'Debug' Option was selected in configuration. A silly mistake.

Make sure 'Release' is selected in this configuration when you publish: Select 'Release' option in Configuration

Upvotes: 1

Matt Becker
Matt Becker

Reputation: 2368

None of the above worked for me. In my case, someone had set the configurations of all projects to point to debug. I reverted the changes and it worked. So if the above solutions do not work for you, check your Configuration Manager and verify that the Configuration is set correctly. enter image description here

Upvotes: 1

Jalal Said
Jalal Said

Reputation: 16162

When #if DEBUG, the code will be omitted out to gray scale when you are in release mode, you can see that your self using the visual studio IDE. if that is not the case them maybe like @Kragen suggested that you define DEBUG somewhere in your class so it affect the release too.

Upvotes: -1

Chad La Guardia
Chad La Guardia

Reputation: 5164

You should be able to select the release mode in your project properties. Right click your project, select Properties and click the build tab on the left of the window. From there, you can uncheck the "define DEBUG constant" box. Make sure you do this for the release build, and not the debug mode.

enter image description here

Upvotes: 19

Justin
Justin

Reputation: 86789

This will be because the DEBUG constant is also true for the release mode.

There is nothing special about the build mode - its just a collection of build settings with a name. If you wanted you could create a "Release" mode with all of the normal "Debug" mode settings (and visa versa).

Upvotes: 0

Lucero
Lucero

Reputation: 60276

Seems like you're answering your own question:

For the project, define DEBUG constant is set to true.

This should only be set conditionally in the build file, and not always.

Upvotes: 5

Related Questions