我的 web.config 文件包含这个
<compilation debug="false" targetFramework="4.0">
<assemblies>
// some assemblies
</assemblies>
</compilation>
在我的 _Layout.cshtml 文件中我有
@{#if DEBUG}
// include all css and js files
@{#else}
// include the minified and combined versions of the css and js files
@{#endif}
问题是 @{#if DEBUG} 分支被执行。如果我将该分支更改为 @{#if !DEBUG},则 else 分支将被执行。这是为什么?
谢谢。
萨钦
最佳答案
Web.config debug=""
属性不会影响预处理器符号。
您可以像这样直接检查该属性:
var compilation = WebConfigurationManager.GetSection("system.web/compilation") as CompilationSection;
return compilation != null && compilation.Debug;
(您应该将其放入任何类的静态属性中,然后在正常的 if
语句中检查该属性)
关于html - @{#if DEBUG} 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9520976/