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?
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.
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
Now if the debug="false"
and with compilerOptions="/define:Debug=True"
the results are
false
defined Debug = true is on
if the debug="true"
and compilerOptions="/define:Debug=True"
the resuls are
true
defined Debug is on
defined Debug = true is on
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With