关闭发布版本的 MVC 编译调试
本文关键字:MVC 编译 调试 版本 布版本 | 更新日期: 2023-09-27 18:36:48
我的MVC 5项目有三个配置文件。 web.config
,web.debug.config
和web.release.config
。
我想在发布中运行时关闭compilation debug
,但似乎无法让它工作。
在 web.config 中
<compilation debug="true"/>
In web.release.config
<compilation debug="false"/>
当我在发布模式下运行时,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>
在你的web.config
中:
<compilation debug="true" ...
在您的web.release.config
:
<compilation xdt:Transform="RemoveAttributes(debug)" />
这将在 compilation
标记上的 debug
属性上设置transform
,以便对其进行remov
。您无需在web.debug.config
中设置任何转换,因为您不希望在调试模式下更改配置。
完成此操作后,发布(部署)项目。若要对其进行测试,请将项目发布到文件夹,然后打开该文件夹的web.config
。您将看到web.config
已转换。配置转换是一项部署功能。
更多信息在这里: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations