【问题标题】:Trying to replace connectionStrings element for continous deployment in Visual Studio Team Services尝试在 Visual Studio Team Services 中替换 connectionStrings 元素以进行持续部署
【发布时间】:2016-09-25 19:47:34
【问题描述】:

我正在使用 Visual Studio Team Services(以前的 Visual Studio Online)来持续部署我的 Web 应用程序。我已经尝试设置 web.config 转换,我相信在我将配置设置更改为 Release | 后它可以工作。此处指示的任何 CPU Web config transforms not working with Visual Studio online, VS2013 and Azure

我相信我遇到的问题更多是关于改造它的自我。

现在我的 web.config 中有以下内容

<connectionStrings configSource="connections.config"/>

我想要这个,这样我就可以避免签入connections.config 并且仍然在本地设置我的数据库连接。我想要做的是用类似这样的代码替换上面的代码行。

<connectionStrings>
    <add name="umbracoDB" connectionString="blah " providerName="System.Data.SqlClient" />
    <add name="EFdb" connectionString="blah" providerName="System.Data.EntityClient" />
</connectionStrings>

我正在使用

&lt;connectionStrings configSource="connections.config" xdt:Transform="Remove" xdt:Locator="Match(configSource)"/&gt; 它似乎成功地删除了 configSource connectionStrings 元素。但是我仍然对如何添加我的替换连接字符串和添加元素感到困惑?

德文

【问题讨论】:

    标签: c# .net azure web-config azure-devops


    【解决方案1】:

    您可以做的一件事是将数据库连接字符串作为秘密变量存储在 Build/Release 中,然后使用 Marketplace 中的 Tokenizer 任务 用实际字符串替换连接字符串标记。

    Tokenizer 任务支持 Release Management 中的环境。

    【讨论】:

    • 为什么不直接使用 Azure 中内置的连接字符串功能?
    • 当然,如果你能利用它的话。我之前/不知道这一点,所以提到了一个通用的解决方案,即使不是 Azure 也可以工作。
    【解决方案2】:

    如果您想在部署期间替换您的 connectionStrings 元素,请尝试使用替换转换:

    <connectionStrings xdt:Transform="Replace">
      <add name="umbracoDB" connectionString="blah " providerName="System.Data.SqlClient" />
      <add name="EFdb" connectionString="blah" providerName="System.Data.EntityClient" />
    </connectionStrings>
    

    【讨论】:

    • 太棒了,效果很好,现在我可以使用我的 Azure 连接字符串来覆盖并且可以让我的连接字符串不受源代码控制。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多