【问题标题】:Release Management for Visual Studio - Remove Web.Config KeyVisual Studio 的发布管理 - 删除 Web.Config 密钥
【发布时间】:2015-06-15 17:29:12
【问题描述】:
在 Visual Studio 2013 发布管理的构建过程中,从 web.config 中删除密钥的推荐方法是什么?
使用 web.config 转换,还是为 web.config 中的整行添加一个令牌(而不是使用令牌作为值)?
Web.config 转换:
<connectionStrings>
<add name="myConnectionString" connectionString=""
xdt:Transform="Remove" xdt:Locator="Match(name)"/>
</connectionStrings>
代币替换:
__myConnectionString__
【问题讨论】:
标签:
visual-studio
tfs
msbuild
release-management
ms-release-management
【解决方案1】:
您应该对希望在构建时发生的事情使用转换。就像删除您仅在开发中使用的任何位一样。
我通常有硬编码的本地值,然后在转换期间用发布管理密钥替换它们。然后 RM 可以拥有其余部分。
【解决方案2】:
我不确定 推荐的方式,但我推荐的在构建期间更改 Web.config 的方式是使用 Web.config transform。因此,在 Web.Release.config 中(不要忘记,如果您正确地进行持续交付,您的构建可能会一直存在,因此您需要构建为发布版本)您可能有类似这样的连接字符串:
<connectionStrings>
<add name="My ConnectionString"
connectionString="Data Source=__DATA_SOURCE__;Initial Catalog=__INITIAL_CATALOG__;Integrated Security=SSPI;"providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"xdt:Locator="Match(name)"/>
</connectionStrings>
这会在构建之后在 Web.config 中生成连接字符串的标记化版本,因此如果您想要一些不同的东西,例如完全删除它们,显然使用 Remove 转换。您可以在我的博文here 中更深入地了解这一点。请注意,我将转换与 /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false MSBuild 参数结合使用。