当我将 ASP.NET Web 应用程序部署到生产环境时,我使用配置转换来删除 debug="true"
来自 <compilation>
.但是,就在今天,我注意到 web.config 中的另一个部分如下所示:
<system.codedom>
<compilers>
<compiler compilerOptions="/define:Debug=True" />
</compilers>
</system.codedom>
这是什么?这是否违背了将其从
<compilation>
中删除的目的? ?如果我如上所示删除该属性会发生什么?
最佳答案
Is the fact that that's there defeating the purpose of removing it from
<compilation>
来自 MSDN C# Compiler Options
打开调试 编译器上的标志是
/debug
不是 /define:Debug=True
/debug : Instruct the compiler to emit debugging information.
/define : Defines preprocessor symbols.
所以当你定义
Debug=True
你只在这种情况下实现代码:#if DEBUG == true
// Compile what is inside here !
#endif
/define:Debug=True
不添加任何额外的调试信息,除非您在上面的代码中手动包含了它们。测试页
我使用以下代码进行测试,看看会发生什么。
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
结果 1
现在如果
debug="false"
并与 compilerOptions="/define:Debug=True"
结果是false
defined Debug = true is on
结果 2
如果
debug="true"
和 compilerOptions="/define:Debug=True"
结果是true
defined Debug is on
defined Debug = true is on
结果 3
现在我再做一个测试,我在 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" />
结果是
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
看着MSDN for the /define (Preprocessor Definition)我看声明
/define:Debug=True
仅适用于这种代码情况
#if DEBUG == true
txtDebug.Text += "<br>defined Debug = true is on";
#endif
关于asp.net - system.web.compilation.debug vs. system.codedom.compilers.compiler.compilerOptions/define :Debug=True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15908579/