Azure Devops 发布管道 XML 变量替换不起作用

Azure Devops Release Pipeline XML Variable Substitution not working

我的发布管道中有一个非常简单的变量替换,但它不起作用。我在 connectionStrings.config 文件中有这样的变量:

<?xml version="1.0"?>
<connectionStrings>
  <add name="ExpenseDBConnectionString" connectionString="__ProdConnString__" providerName="System.Data.SqlClient" />
</connectionStrings>

然后我在发布管道中定义了变量:

我还在部署任务中启用了 XML Variable Substitution

但是我 运行 发布了,变量没有被替换。我在日志中收到此消息:

2020-02-28T19:57:26.1262198Z Initiated variable substitution in config file : D:\a\_temp\temp_web_package_875508750741006\Content\D_C\a\s\Expenses.Web\obj\Release\Package\PackageTmp\App_Config\ConnectionStrings.config
2020-02-28T19:57:26.1312311Z Processing substitution for xml node : connectionStrings
2020-02-28T19:57:26.1321602Z Skipped Updating file: D:\a\_temp\temp_web_package_875508750741006\Content\D_C\a\s\Expenses.Web\obj\Release\Package\PackageTmp\App_Config\ConnectionStrings.config

这应该很简单,所以不确定我缺少什么设置。求助!

 XML transformation will be run on the *.config file for transformation configuration files named *.Release.config or *.<stage>.config

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic#xml-transformation

这应该是你的答案?你的文件名不是这样的。

您应该在发布管道中将变量名称定义为 ExpenseDBConnectionString。以下是设置 XML variable substitution 的说明。变量与 keyname 条目匹配

Variables defined in the build or release pipeline will be matched against the 'key' or 'name' entries in the appSettings, applicationSettings, and connectionStrings sections of any config file and parameters.xml. Variable Substitution is run after config transforms.

所以定义的变量应该如下所示:

下面的截图是我测试发布的结果,你可以看到connectionString被替换了。

有关XML变量替换的更多信息,请查看here

还有一些第三方替换工具(即。Magic Chunks) that you can use to replace your config settings. Please check out the example for this thread