gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:54:32 27 4
gpt4 key购买 nike

当我将 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com