问题
I have a very simple variable substitution in my release pipeline, but it's not working. I have the variable in the connectionStrings.config
file as such:
<?xml version="1.0"?>
<connectionStrings>
<add name="ExpenseDBConnectionString" connectionString="__ProdConnString__" providerName="System.Data.SqlClient" />
</connectionStrings>
I then have the variable defined in the release pipeline:
I also have the XML Variable Substitution
enabled in the Deploy Task:
But I run the release, and the variable doesn't get substituted. I get this message in the logs:
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
This should be pretty simple, so not sure what setting I am missing. Help!
回答1:
You should define your variable name as ExpenseDBConnectionString
in the release pipeline. Below is the description of the setting XML variable substitution
. The variables are matched against the key
or name
entries
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.
So the variable defined should be like below:
Below screenshot is the result from my test release, you can see the connectionString was replaced.
For more information about XML variable substitution, please check it out here.
There are also some third party substitution tools(ie. Magic Chunks) that you can use to replace your config settings. Please check out the example for this thread.
回答2:
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
That should be your answer? Your file name is not like that.
来源:https://stackoverflow.com/questions/60458615/azure-devops-release-pipeline-xml-variable-substitution-not-working