关闭发布版本的MVC编译调试

Chr*_*ris 3 c# asp.net debugging asp.net-mvc

我的MVC 5项目有三个配置文件.web.config,web.debug.configweb.release.config.

我想compilation debug在发布时运行时关闭,但似乎无法让它工作.

在web.config中

<compilation debug="true"/>
Run Code Online (Sandbox Code Playgroud)

在web.release.config中

<compilation debug="false"/>
Run Code Online (Sandbox Code Playgroud)

当我在发布模式下运行时HttpContext.Current.IsDebuggingEnabled仍然等于true(仍然附加到调试器).

我究竟做错了什么?我试图将标签从主要标签中取出web.config并放入,web.debug.config但调试器只是抱怨并要求我将其重新放入web.config

更新

我的web.release.config看起来像这样

<system.webServer>
  <httpErrors errorMode="Custom">
    <remove statusCode="404" />
    <error statusCode="404" path="/error/notfound" responseMode="ExecuteURL" />
    <remove statusCode="403" />
  <error statusCode="403" path="/error/forbidden" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
  <compilation xdt:Transform="RemoveAttributes(debug)" />
  <!--<compilation debug="false"/>-->
</system.web>
Run Code Online (Sandbox Code Playgroud)

Abh*_*lks 7

在你的web.config:

<compilation debug="true" ...
Run Code Online (Sandbox Code Playgroud)

在你的web.release.config:

<compilation xdt:Transform="RemoveAttributes(debug)" />
Run Code Online (Sandbox Code Playgroud)

这将在标签transform上设置on debug属性.您不需要在您的设置中设置任何变换,因为您不希望在调试模式下更改配置.compilationremovweb.debug.config

Once done that, publish (deploy) your project. To test it, publish your project to a folder and then open up the web.config there. You will see that the web.config has been transformed. Config-transforms are a deployment feature.

More info here: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations