首页 > 解决方案 > 使用 VSTS 发布定义替换列表中的多个变量

问题描述

我目前在 VSTS 中使用变量替换,但是我遇到了如何从列表中选择特定元素的障碍。

我必须同时提供要替换的变量的名称和替换旧值的键。我可以用来.在配置中选择嵌套元素。

我有以下 app.config。

<services>
  <service behaviorConfiguration="ServiceBehaviour" name="Application.Project01">
    <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="web" contract="Application.Interface01">
      <identity>
        <dns value="dns01" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Project01/" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="ServiceBehaviour" name="Application.Project02">
    <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="web" contract="Application.Interface02">
      <identity>
        <dns value="dns01" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Project02/" />
      </baseAddresses>
    </host>
  </service>
</services>

我希望能够单独替换这些服务中的每一项中的变量。我感兴趣的特定键是services.service.endpoint.identity.dns.valueservices.host.baseaddresses.add.baseaddress

我尝试了以下方法来编辑 dns 值

我正在使用的任务是 Azure App Service Deploy 版本 3。*

标签: azure-devopsazure-pipelines-release-pipeline

解决方案


对于Azure App Service Deploy 任务的XML 变量替换功能,它仅对配置文件的 applicationSettings、appSettings、connectionStrings 和 configSections 元素生效。

所以你不能用它来达到你的要求。

您可以尝试使用 XML 转换。

您也可以尝试使用其他任务,例如发布管理实用程序任务其他


推荐阅读