【问题标题】:Add a new connection string via MSBuild通过 MSBuild 添加新的连接字符串
【发布时间】:2016-06-29 23:18:29
【问题描述】:

我想使用 MSbuild 目标任务添加一个新的连接字符串(如果存在,则用确切的名称替换它)。我知道MSbuild包含XmlPoke,但是命令可以修改一些节点或属性,但是如何添加一个新的呢?

之前:

<connectionStrings>      
    <add name="myDB" connectionString="myCredentials"/>
</connectionStrings>

之后:

<connectionStrings>      
    <add name="myDB" connectionString="myCredentials"/>
    <add name="myCustomKeyAddedDuringMSBuild" connectionString="key=someCredentials" />
</connectionStrings>

但如果我的目标配置文件已经包含“myCustomKeyAddedDuringMSBuild”连接字符串,那么什么都不做。

【问题讨论】:

    标签: .net msbuild connection-string


    【解决方案1】:

    如果您可以使用 XDT 转换您的配置文件,那么您可以使用 xdt:transform="InsertIfMissing"。 例如:

    <add name="myCustomKeyAddedDuringMSBuild" 
        connectionString="key=someCredentials" xdt:transform="InsertIfMissing" 
        xdt:Locator="Match(name)" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 2015-10-17
      相关资源
      最近更新 更多