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

标签 azure azure-devops azure-pipelines devops variable-substitution

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

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

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

enter image description here

我还在部署任务中启用了 XML 变量替换:

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

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

最佳答案

您应该在发布管道中将变量名称定义为 ExpenseDBConnectionString。以下是设置 XML 变量替换 的说明。变量与 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.

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

enter image description here

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

enter image description here

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

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

关于Azure Devops 发布管道 XML 变量替换不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60458615/

相关文章:

Azure 暂存环境基础设施 - 我可以暂停它吗?

azure 无法在 devops 中重用订阅

node.js - 在自托管 VSO 代理上运行 NPM

TFS 构建工件正在消失

azure-devops - 如何指向 Azure Pipelines 构建的引用存储库上的特定提交

.net-core - AzureDevOps - 无法作为单个文件发布

android - 如何在 Azure Devops 管道中运行 Espresso UI 测试

azure - AZ CLI 备份策略保留时间不保存超过 7 天

Azure 数据工厂压缩而不创建文件夹

azure - 使用 Azure Key Vault 而不仅仅是应用程序配置有什么意义?