为什么有些Web.config转换将标记化为SetParameters.xml,而另一些却没有? [英] Why are some Web.config transforms tokenised into SetParameters.xml and others are not?

查看:87
本文介绍了为什么有些Web.config转换将标记化为SetParameters.xml,而另一些却没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在VS2010中使用了config转换,但是对于为什么将某些转换直接应用到包中的Web.config却为什么将某些转换存储在SetParameters.xml中的令牌中却又在发布时应用了混淆感到困惑

I've been using config transforms in VS2010 quite a bit lately but am confused as to why some transforms are applied directly to the Web.config in the package but others are stored against a token in SetParameters.xml then applied on publish.

例如,使用具有以下连接字符串和应用程序设置的Web.config:

For example, take a Web.config with the following connection string and app setting:

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

这是当前构建配置的相应配置转换:

Then here's the corresponding config transform for the current build configuration:

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

这些都是替换"转换,一个是与名称"匹配的连接字符串,另一个是与键"匹配的应用设置,在我看来,它们是相同的.

These are both "Replace" transforms and other than one being a connection string matching on "name" and the other being an app settings matching on "key", to my eye they're identical.

现在查看结果包中的SetParameters.xml文件,只有连接字符串具有setParameter节点.在PackagTmp文件夹的Web.config中,已经应用了应用程序设置转换,而连接字符串具有"$(ReplacableToken_AutoDeployDb-Web.config连接字符串_0)"值,该值仅在部署程序包时才应用.

Now look inside the SetParameters.xml file in the resultant package and only the connection string has a setParameter node. In the Web.config of the PackagTmp folder, the app setting transform has already been applied while the connection string has a "$(ReplacableToken_AutoDeployDb-Web.config Connection String_0)" value which is applied only when the package is deployed.

这是为什么?它是特定于连接字符串(或相反,特定于应用程序设置)的东西吗?我感谢此方法的合理性,我不清楚为什么将它应用于某些设置而不是其他设置.

Why is this? Is it something specific to connection strings (or conversely, to app settings)? I appreciate the rationale of this approach, I'm just not clear on why it's applied to some settings and not others.

任何人都可以对此有所了解吗?

Can anyone shed some light on this?

推荐答案

这实际上与配置转换无关.我刚刚在 http://sedodream.com/2010/11/11上发布了非常详细的博客/ASPNETWebApplicationPublishPackageTokenizingParameters.aspx .但是这里有一些适合您的信息.

This actually has nothing to do with config transforms. I just posted a very detailed blog at http://sedodream.com/2010/11/11/ASPNETWebApplicationPublishPackageTokenizingParameters.aspx. But some info here for you.

在Web发布管道(WPP)中,我们将连接字符串视为特殊工件..我们将自动为您为所有连接字符串创建参数.这是因为在许多情况下,当您部署应用程序时,您想更改连接字符串.我们不会自动为任何appSettting值创建参数.现在回到您的问题,为什么我们标记连接字符串?我们确实在这样做,以确保您不会错过设置该值,然后意外地让您的应用程序更新了错误的数据库.通过为您创建这些参数,我们可以为您提供帮助.您也可以根据需要禁用此行为.您可以将MSBuild属性 AutoParameterizationWebConfigConnectionStrings 设置为false.

In the Web Publishing Pipeline (WPP) we handle connection strings as special artifacts. We will automatically create parameters for you for all connection strings. This is because in many cases when you deploy your app you want to change the connection strings. We do not automatically create parameters for any appSettting value. Now back to your question why do we tokenize the connection strings? We are really doing this to make sure that you do not miss setting the value and then accidentally have your application updating the wrong DB. We do help you by creating those parameters for you. Also you can disable this behavior if you want. You can set the MSBuild property AutoParameterizationWebConfigConnectionStrings to false.

这篇关于为什么有些Web.config转换将标记化为SetParameters.xml,而另一些却没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆