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

标签 asp.net debugging configuration web-config

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

相关文章:

c# - 在 asp.net 中结合代码绑定(bind) css 类和页面 css 类

javascript - 单击 img 时更改 onLoad 正文

Asp.Net:在 iis 中调试网站

java - 为什么 Spring propertyplaceholder 没有检测到我对系统属性的更改?

java - 以编程方式更改 log4j2 ROOT 记录器,添加 AppenderRef + ThreadContextMapFiler 值

hibernate - 是否必须有 hibernate.cfg.xml 文件进行配置

希望进入 SharePoint 的 ASP.NET 开发人员 - 2007 或 2010?

c# - ORM 的哪些选择允许接近 'flick a switch' 在...SQL Server/SQL Azure 和 PostgreSQL/'Cloud' PostgreSQL 之间更改 RDBMS

c++ - 在 WinDbg 中开始调试的基本设置+任务是什么?

xcode - TestFlight 和发布运行崩溃?