[英]web.config transforms not being applied on either publish or build installation package
今天,我开始在VS 2010中使用web.config
转换。首先,我尝试了相同的hello world示例,该示例在许多有关此主题的博客文章中都使用-更新连接字符串。
我创建了下面显示的最小示例(与本博客中的示例类似)。 问题是,每当在.csproj文件上单击鼠标右键->“发布”,或单击鼠标右键->“构建部署程序包”时,都不会得到正确的输出。 我没有得到任何 web.config,而不是经过转换的web.config,而是包括了两个转换文件。
我究竟做错了什么? 任何帮助表示感谢!
Web.config:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="ConnectionString"
connectionString="server=(local); initial catalog=myDB;
user=xxxx;password=xxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
Web.debug.config:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ConnectionString"
connectionString="server=DebugServer; initial catalog=myDB;
user=xxxx;password=xxxx"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Web.release.config:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ConnectionString"
connectionString="server=ReleaseServer; initial catalog=myDB;
user=xxxx;password=xxxx"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
不可避免地,这些事情的答案实际上是盯着我。 web.config的<configuration>
节点中存在xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
意味着我的转换不匹配。 删除它解决了问题。
在您的web.release.config和web.debug.config文件中,将相同的名称空间添加到您的转换中,
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
...
对我来说,这是:
(1)菜单Build-Configuration Manager
(2)在我的情况下选择有效的解决方案发布并正确配置它(我在那里选择了Debug,因此未应用Publish的任何转换)
我遇到了类似的问题,而修复的原因是因为我为我的环境设置了“解决方案配置”,但是我从未创建与解决方案配置匹配的项目配置。
去检查:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.