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

时间:2020-02-28 20:10:27

标签: azure azure-devops azure-pipelines devops variable-subsitution

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

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

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

enter image description here

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

enter image description here

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

2020-02-28T19:57:26.1262198Z Initiated variable substitution in config file : D:\a\_temp\temp_web_package_875508750741006\Content\D_C\a\1\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\1\s\Expenses.Web\obj\Release\Package\PackageTmp\App_Config\ConnectionStrings.config

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

2 个答案:

答案 0 :(得分:3)

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

在构建或发布管道中定义的变量将与任何配置文件和parameters.xml的appSettings,applicationSettings和connectionStrings部分中的“ key”或“ name”条目匹配。在配置转换后运行变量替换。

因此定义的变量应如下所示:

enter image description here

下面的屏幕快照是我的测试版本的结果,您可以看到connectionString被替换了。

enter image description here

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

还有一些第三方替代工具(即Magic Chunks)可用于替换您的配置设置。请查看this thread的示例。

答案 1 :(得分:0)

 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

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

相关问题