I have a deployed ASP.NET site. The compilation
setting for debug
is set to false
. I have some code that checks the DEBUG
define and it is reporting true
.
Why? What do I need to do for this to be false
?
This used to work but ever since I upgraded my website from .NET 2.0 to .NET 3.5, I see this problem. Note that the server was always .NET 3.5.
Update
As already stated above, in my web.config file debug
is false
(I understand the the DEBUG preprocessor symbol and the web.config setting are not related). In addition, the Configuration Manager of VS2010 only provides Debug as a configuration for the website and any attempt to add Release is overwritten by VS2010.
I just realised one other detail; I am using SP1 beta of VS2010. Perhaps this is causing the problem?
I have now also realized that Emit Debug Information does not only create PDB files but also enable any code running within #if DEBUG clause (as if compilation debug=true in web.config). This compilation option does not affect other projects in your solution as long as it is compiled in Release mode.
In order to gain the benefits of having your web sites PDB files without enabling DEBUG code blocks you should not deploy your web site with the Emit Debug Information and rather publish the web site after specifying compilerOptions="/debug:pdbonly" in your web.config file. specify also /optimize- to make sure line number are same as in your code
Code sample:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
compilerOptions="/optimize- /debug:pdbonly">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="WarnAsError" value="false" />
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="OptionInfer" value="true" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
There is another work around for compiling your web site with PDB files but without enabling DEBUG code and that is by wrapping DEBUG code blocks in if (Consts.DEBUG) clause.
Where in your App_Code file there a CS file containing following code:
public static class Consts
{
static bool _bIsInDebugMode = false;
static Consts()
{
var oConfigSection = System.Configuration.ConfigurationManager.GetSection("system.web/compilation") as System.Web.Configuration.CompilationSection;
_bIsInDebugMode = oConfigSection != null && oConfigSection.Debug;
}
public static bool DEBUG { get { return _bIsInDebugMode; } }
}
Now replace any #if DEBUG ... #endif
code block with if (Consts.DEBUG) { ... }
You need to change your solution configuration to "Release" in Visual Studio. The compilation
setting applies only to the dynamically compiled pages and controls.
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