加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:04:11 所属栏目:百科 来源:网络整理
导读:我的MVC 5项目有三个配置文件. web.config,web.debug.config和web.release.config. 我想在发布时运行时关闭编译调试,但似乎无法让它工作. 在web.config中 compilation debug="true"/ 在web.release.config中 compilation debug="false"/ 当我在发布模式下运
我的MVC 5项目有三个配置文件. web.config,web.debug.config和web.release.config.

我想在发布时运行时关闭编译调试,但似乎无法让它工作.

在web.config中

<compilation debug="true"/>

在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)" />

这将在编译标记上设置debug属性的转换,以便将其删除.您无需在web.debug.config中设置任何转换,因为您不希望在调试模式下更改配置.

完成后,发布(部署)您的项目.要测试它,将项目发布到文件夹,然后在那里打开web.config.您将看到web.config已被转换.配置转换是一种部署功能.

更多信息:http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读