我一直在最近使用VS2010中的配置转换,但很困惑,为什么有些转换直接应用于包中的Web.config,但其他转换则存储在SetParameters.xml中的令牌中,然后应用于发布。为什么某些Web.config转换标记为SetParameters.xml而其他标记不是?
例如,拿一个Web.config与下面的连接字符串和应用程式设定:
<connectionStrings>
<add name="AutoDeployDb" connectionString="Data Source=(local);Initial Catalog=AutoDeploy;User ID=AutoDeployUser;Password=Passw0rd"/>
</connectionStrings>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
</appSettings>
然后这里的相应配置变换当前构建配置:
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)" name="AutoDeployDb" connectionString="Data Source=MyDevServer;Initial Catalog=AutoDeploy;User ID=AutoDeployUser;Password=s*#@Kdsl" />
</connectionStrings>
<appSettings>
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="ChartImageHandler" value="storage=file;timeout=20;dir=d:\inetpub\AutoDeploy\TempImageFiles\"/>
</appSettings>
这些都是“替换”变换,而不是一个是“name”匹配的连接字符串,另一个是与“key”匹配的应用程序设置,在我看来,它们是相同的。
现在查看生成包中的SetParameters.xml文件,只有连接字符串具有setParameter节点。在PackagTmp文件夹的Web.config中,应用程序设置转换已经应用,而连接字符串具有仅在部署包时应用的“$(ReplacableToken_AutoDeployDb-Web.config连接String_0)”值。
这是为什么?它是特定于连接字符串(或相反,应用程序设置)的东西吗?我很欣赏rationale of this approach,我只是不清楚它为什么适用于某些设置而不适用于其他设置。
任何人都可以对此有所了解吗?
如果有一种简单的方法(通过MSBuild属性)以这种方式处理appSettings(无论是特定的还是整个集合),这将是非常有用的。例如AutoParameterizationAppSettings = true。 – 2011-05-25 23:23:05
这篇文章很好的定义了解决我的问题的方法:http://vishaljoshi.blogspot.com/2010/07/web-deploy-parameterization-in-action.html – 2011-05-25 23:37:38
但是为什么有人想要这样? – 2012-03-26 14:00:02