C # preprocessor not working

#if(DEBUG) ......Code...... #else ......Code...... #endif 

I have a code like this. if my application runs in debug mode, it must execute the #if(DEBUG) , if it is running in Release mode, it must execute the #else part. but no matter what mode it executes, only the #if(DEBUG) part is executed.

I am using a WPF application with VS2010

Can anybody help me?

+6
c # c-preprocessor
source share
5 answers

To configure debugging, your project settings should look like

enter image description here

For release, they should look like this:

enter image description here

Can you verify that this is the case and let us know if that is so? If not, what is there for each configuration?

+14
source share

Create a new project using all the default settings and make sure that you can do this job properly. If so, your problematic project should somehow be “damaged”, perhaps by defining the DEBUG constant in the release configuration or by choosing the debug project configuration for the release solution configuration.

+3
source share

It depends on how you create your configurations. For example, if you create your own configuration and use debug or release as a template, DEBUG or RELEASE will be copied to a specific constraint element. It will not change the element of certain restrictions (in the project file) to the new configuration name.

Open the project file and find the configuration sections. Verify that the platform below has the value "PROD" in the DefineConstants element. If the directives of the preliminary compiler are executed in the code, then they will not work in the code.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PROD|x86'"> <DefineConstants>PROD;TRACE</DefineConstants> <OutputPath>bin\x86\PROD\</OutputPath> </PropertyGroup> 
+1
source share

I would suggest that in your project properties under Build you noted Define DEBUG constant .

Try setting the configuration mode to Release and run the application again. The default value for Release is that the DEBUG constant is not defined unless you faked, unless, of course;)

If Define DEBUG constant not checked, then you have #define DEBUG somewhere hidden.

So, two things. Check the constant in the parameters in the "Release mode" section and check for the presence of a constant constant manually. This must be one of them.

0
source share

Why do you put DEBUG between parentheses?

 #if DEBUG Code #else Code #endif 
0
source share

All Articles