繁体   English   中英

Web.config转换不转换VS 2017

[英]Web.config transform not transforming VS 2017

我实际上没有注释样板代码并尝试发布到文件系统以检查“转换”是否有效。

但是,它不会转换web.config文件。 我在这里看了一些文章和答案,但无法让它发挥作用。

我试过的事情:

Removing the namespace from the configuration node(complains about xdt missing)
Creating a new transform file(production)
Creating a new configuration(production)

这是web.Release.config:

<?xml version="1.0"?>

<!-- For more information on using Web.config transformation visit https://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 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>
  -->
      <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>

我收到以下错误:

No element in the source document matches '/configuration/connectionStrings/add[@name='MyDB']'

但正如您所看到的那样,它存在于添加节点中。

有什么建议吗? 我很困惑为什么它不起作用。

编辑: web.config连接字符串

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;database=smartDB;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

name属性的值需要在web.configweb.release.config之间匹配,因为您在转换配置中指定了Match(name)

在你的web.config中你有: name="DefaultConnection"在web.release.config中: name="MyDB"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM