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

当我将ASP.NET Web应用程序部署到生产环境时,我使用配置转换从< compilation>中删除debug =“true”.但是,就在今天我注意到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时,您只能将此情况设为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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....