Deployed ASP.NET site has DEBUG true
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 alr开发者_如何学编程eady stated above, in my web.config filedebug
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.
I was able to track this down. It seems obvious and curious now that I know the cause.
When publishing the website, there is the option to Emit debug information
. Now, to me, this suggested that the very useful PDB would be emitted, but not an actual debug build. To others, it may seem obvious that this would result in a Debug build, but that was not obvious to me. It didn't even cross my mind until I started tracing every little change I've made in my recent update.
精彩评论