7

When I deploy my ASP.NET web app to production, I use a config transform to remove debug="true" from <compilation>. However, just today I noticed another section in the web.config that looks like this:

<system.codedom>
    <compilers>
        <compiler compilerOptions="/define:Debug=True" />
    </compilers>
</system.codedom>

What is this? Is the fact that that's there defeating the purpose of removing it from <compilation>? What happens if I remove that attribute as shown above?

0

2 Answers 2

6
+50

Is the fact that that's there defeating the purpose of removing it from <compilation>

From MSDN C# Compiler Options
To open the debug the flag on the compiler is the /debug not the /define:Debug=True

/debug : Instruct the compiler to emit debugging information.
/define : Defines preprocessor symbols.

So when you define the Debug=True you only make true this case of code:

#if DEBUG == true
// Compile what is inside here !
#endif

the /define:Debug=True is not add any additional debug informations, unless you have include them manual with the above code.

Test page

I use the following code to make tests and see whats happens.

    txtDebug.Text = HttpContext.Current.IsDebuggingEnabled.ToString();

    #if DEBUG
    txtDebug.Text +=  "<br>defined Debug is on";
    #endif
    #if DEBUG == true
    txtDebug.Text +=  "<br>defined Debug = true is on";
    #endif

Result 1

Now if the debug="false" and with compilerOptions="/define:Debug=True" the results are

false
defined Debug = true is on

Result 2

if the debug="true" and compilerOptions="/define:Debug=True" the resuls are

true
defined Debug is on
defined Debug = true is on

Result 3

Now I make one more test, I add this line on web.config

  <compiler language="c#;cs;csharp" extension=".cs" 
    compilerOptions="/define:Debug=True /D:DEBUG,TESTFLAG" 
   type="Microsoft.CSharp.CSharpCodeProvider, System, 
     Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
       warningLevel="4" />

And the results are with debug=false

False (debug is false)
defined Debug is on (but the defined DEBUG now is runs)
defined Debug = true is on (This is also runs)
test flag (but the defined extra flag is also runs)

MSDN

Looking at the MSDN for the /define (Preprocessor Definition) I look that the declaration

/define:Debug=True

is work only for this case of code

#if DEBUG == true
txtDebug.Text +=  "<br>defined Debug = true is on";
#endif
Sign up to request clarification or add additional context in comments.

5 Comments

Sorry I've put this off. I am not sure I am understanding the use of #if DEBUG. I cannot get this to return false unless I change the configuration dropdown at the toolbar (where you see Debug, Release, etc) and then rebuild. Also, what is the difference between #if DEBUG and #if DEBUG == true? Lastly, what is your final, objecting answer? David Ebbo's answer states that having /define:Debug=True is the same thing as debug="true". Does your answer agree with or contradict his answer?
@oscilatingcretin having debug="true" is not the same as /define:debug=true because have higher priority and the define is not working here for that, and I have made a test page and show the results here that proves it. Now I have also in the answer what is the difference between #if DEBUG and #if DEBUG == true, if you see the test you understand them. I can not write them here again.
@oscilatingcretin Is not the same, and here from msdn is the proof msdn.microsoft.com/en-us/library/6s2x2bzy.aspx and I will update the answer again
Having looked at that and an MSDN doc on Debug=true, I believe you are correct. Awarding you bounty and answer to close this out.
Which is the full code of Test page ? reommended codedom configuration for production environment ?
1

The string you set in compilerOptions is basically a piece of command line that gets added to all compilations.

If you use aspx pages, you can also set it in there so it only applies to one page. e.g.

<%@ Page Language="C#" CompilerOptions="etc..." %>

How did you end up with it set to "/define:Debug=True" in your config? It is not typical to have that. But to answer your question, yes, this will effectively turn on Debug regardless of the value of the debug attribute.

Unless you have a good reason to have it, I would yank it altogether.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.