如何通过VSTS关闭system.web编译调试模式

时间:2018-01-24 04:04:58

标签: c# asp.net azure-web-sites azure-pipelines

我有这个web.config文件,其编译选项设置如下:

<configuration>
...
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
  </system.web>
</configuration>

如何通过VSTS的构建定义将编译的调试标志关闭为假?

更新: 我正在通过VSTS的发布功能将系统部署到Azure服务器。

1 个答案:

答案 0 :(得分:3)

您可以使用转换来实现您想要的效果。 这是文件: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations

以下是您的Web.debug.config文件的外观。如果要在发布模式下使用转换,也可以使用web.release.config。

<?xml version="1.0"?>

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

<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 atrribute "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 debug="false"   xdt:Transform="Replace"/>         

    <!--
      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>