我最近在 VS2010 中使用配置转换相当多,但我很困惑为什么有些转换直接应用于包中的 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>
这些都是“替换”转换,而不是与“名称”和“名称”相匹配的连接字符串另一个是与“key”匹配的应用程序设置,在我看来它们是相同的。
现在查看结果包中的 SetParameters.xml 文件,只有连接字符串具有 setParameter 节点。在 PackagTmp 文件夹的 Web.config 中,已应用应用程序设置转换,而连接字符串具有“$(ReplacableToken_AutoDeployDb-Web.config Connection String_0)”值,该值仅在部署包时应用。
这是为什么呢?它是否特定于连接字符串(或者相反,特定于应用程序设置)?我很欣赏这种方法的基本原理,我只是不清楚为什么它应用于某些设置而不应用于其他设置。
有人能解释一下吗?
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.
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.
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?
发布评论
评论(2)
这实际上与配置转换无关。我刚刚在 http://sedodream.com/2010/11/11 上发布了一篇非常详细的博客/ASPNETWebApplicationPublishPackageTokenizingParameters.aspx。但这里有一些信息供您参考。
在网络发布管道 (WPP) 中,我们将连接字符串作为特殊工件进行处理。我们将自动为您创建所有连接字符串的参数。这是因为在许多情况下,当您部署应用程序时,您想要更改连接字符串。我们不会自动为任何 appSettting 值创建参数。现在回到您的问题,为什么我们要标记连接字符串?我们这样做实际上是为了确保您不会错过设置该值,然后意外地让您的应用程序更新错误的数据库。我们通过为您创建这些参数来帮助您。如果需要,您也可以禁用此行为。您可以将 MSBuild 属性 AutoParameterizationWebConfigConnectionStrings 设置为 false。
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.
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 包导入 IIS 时:
开发和运维之间的责任边界。一方面,您将目标环境的参数(数据库、缓存、AWS key/secret 等)放入操作需要处理的连接字符串中。另一方面,您可以将不相关的选项放在应用程序设置部分,这样可以减轻操作人员对特定产品和业务逻辑的负担。
在我的公司,一名运营人员通常负责多种产品。你确实不能要求他们像你一样了解那么多的产品知识。他们需要关注的事情越少,生活就会越幸福。
Regarding deployment, there's one significant difference between them. When you import web packages to IIS:
The differentiation creates a responsibility boundary between dev and ops. On one hand, you put parameters of target environment (database, cache, AWS key/secret, etc.) in connection strings that ops needs to take care of. On the other hand, you put irrelevant options in app settings section so ops's burden over specific products and business logic can be relieved.
In my company, one ops guy is often responsible for multiple products. You really can't require them to know as much product knowledge as you do. The less thing they need to pay attention, the happier the life will be.