#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 re开发者_如何学Golease 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.
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.
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.
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.
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).
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
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.
精彩评论