asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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>中删除它的目的吗?如果我删除上面显示的属性会怎样?

解决方法

MSDN C# Compiler Options
要打开调试,编译器上的标志是/ debug而不是/ define:Debug = True

因此,当您定义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”并且使用COR_647_11845@pilerOptions =“/ define:Debug = True”,结果是

结果2

如果debug =“true”和compilerOptions =“/ define:Debug = True”结果是

结果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

@H_612_4@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与system.codedom.compilers.compiler.compilerOptions / define:Debug = True全部内容,希望文章能够帮你解决asp.net – system.web.compilation.debug与system.codedom.compilers.compiler.compilerOptions / define:Debug = True所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。