【问题标题】:MVC web.config compilation debug=true - a manual change needed?MVC web.config 编译 debug=true - 需要手动更改吗?
【发布时间】:2015-06-03 08:36:11
【问题描述】:

当使用内置模板(文件 -> 新项目等)创建 MVC 项目时,web.config 会读取

<compilation debug="true" targetFramework="4.5" />

在 Web.Release.config 中我看到了这个转换

<compilation xdt:Transform="RemoveAttributes(debug)" />

所以我假设当我在发布模式下构建时 debug="true" 会消失。但是我没有看到这个。 转换是否仅在发布网站时应用?我见过通过拖放部署的网站,Web.config 从根目录复制过来(包括 debug="true")。

我想检查一下,如果通过拖放进行部署,您是否必须手动删除此属性?还是我错过了什么?

【问题讨论】:

  • xdt:Transform="RemoveAttributes(debug)" 属性指定您希望从部署的 Web.config 文件中的 system.web/compilation 元素中删除调试属性。每次部署发布版本时都会执行此操作。
  • 回答了您的问题?

标签: asp.net-mvc web-config web-deployment


【解决方案1】:

最好是发布您的网站(不同于 F5drag and drop)以便更新\转换 web.config ...

禁用调试模式

取决于构建配置而不是目标环境,debug 属性适用于 Release 构建,特别是当您通常希望禁用调试时,无论您要部署到哪个环境。

Visual Studio 项目模板将创建一个 Web.Release.config 转换文件,其中包含从编译元素中删除调试属性的代码。

在默认的 Web.Release.config 之下:(带有一些被注释掉的示例转换代码,它包括在编译元素中删除调试属性的代码:)

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit     http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value     of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an attribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial     Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>

【讨论】:

  • 所以通过拖放,您将不得不手动编辑配置。
  • 编辑您的答案以将您对拖放场景的评论放入(这是问题)并提到首选方式是通过发布选项,它将转换应用于配置,我将其标记为答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-20
  • 2015-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多