Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

system.web.compilation.debug vs. system.codedom.compilers.compiler.compilerOptions /define:Debug=True

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?

like image 372
oscilatingcretin Avatar asked Apr 09 '13 17:04

oscilatingcretin


1 Answers

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
like image 181
Aristos Avatar answered Sep 20 '22 16:09

Aristos