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

When I deploy the ASP.NET web application for production, I use the configuration transform to remove debug="true" from <compilation> . However, only today I noticed another section in the web.config file, which looks like this:

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

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

+6
source share
2 answers

Is the fact that this defeats the goal of removing it from <compilation>

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

/ debug: Ask the compiler to fix the debug information.
/ define: Defines preprocessor characters.

So, when you define Debug=True , you only do this code code:

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

/define:Debug=True does not add additional debugging information unless you include a manual with the above code in it.

Testing Page

I use the following code to run tests and view events.

  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 debug="false" and with compilerOptions="/define:Debug=True" results

falsely
specific Debug = true enabled

Result 2

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

right
a specific debugger is on
specific Debug = true enabled

Result 3

Now I am doing another test, I am adding this line to 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 with debug=false

False (debug is false)
defined debug enabled (but defined debug is now running)
defined by Debug = true enabled (this also runs)
test flag (but a specific optional flag is also triggered)

MSDN

Looking at the MSDN for / define (preprocessor definition) I look at the declaration

 /define:Debug=True 

only works for this code case

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

The line set in compilerOptions is basically part of the command line that is added to all compilations.

If you use aspx pages, you can also set it there so that it only refers to one page. eg.

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

How did you end up setting / config: Debug = True to "config"? This is not typical. But to answer your question, yes, this will effectively enable Debug regardless of the value of the debug attribute.

If you have no good reason for this, I would have completely pulled it out.

+1
source

All Articles