gpt4 book ai didi

c# - Web.config 转换不转换 VS 2017

转载 作者:太空宇宙 更新时间:2023-11-03 22:57:19 24 4
gpt4 key购买 nike

我确实取消了样板代码的注释并尝试发布到文件系统以检查“转换”是否有效。

但是,它不会转换 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.config 之间匹配和 web.release.config ,因为您指定的是 Match(name)在转换配置中。

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

关于c# - Web.config 转换不转换 VS 2017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44768221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com