【发布时间】:2015-08-17 20:41:20
【问题描述】:
我有一个 CI 服务器(Bamboo,但我认为这并不重要)构建和自动部署我的应用程序。在本地开发期间,我使用 localdb(web.config 中的<connectionStrings> 节点)
<add name="MyApp" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30;Initial Catalog=MyApp" />
<add name="MyApp_Patients" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30;Initial Catalog=AppleHms_MyApp" />
...
显然在部署时不应该使用它。它应该使用我的部署 sql server 连接字符串。
我知道我可以为此编写一个 web.config 转换,我什至知道我可以加密 web.config,但我不确定 db 连接字符串应该如何正确进入那里。对我来说有意义的是 CI 服务器覆盖每个 connectionString - 所以我的配置转换应该看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyApp" providerName="System.Data.SqlClient" connectionString="${main-db-connectionstring}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<add name="MyApp_Patients" providerName="System.Data.SqlClient" connectionString="${patients-db-connectionstring}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
...
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
覆盖来自我的 ci 服务器中的变量(可能是 msbuild 或 deploy 的某些部分)?
这是正确的“正确”方式吗?究竟我与 msbuild/deploy 有什么关系才能做到这一点?
【问题讨论】:
标签: .net msbuild continuous-integration msdeploy