Azure Devops Release Pipe line XML variable substitution not working - azure

I want to substitute the key "DevConnectionString" before deployment to serve from Release pipeline.
<appSettings>
<add key="DevConnectionString" value="xyz"/>
</appSettings>
I have checked XML variable substitution
XML variable substitution
And also created a release variable "DevConnectionString"
Release variable
But after deployment "DevConnectionString" value not getting changed. Its showing old value.
I valve checked log. Its showing Skipped Updating file web.congif
Initiated variable substitution in config file : ...\obj\Release\Package\PackageTmp\Web.config
Processing substitution for xml node : appSettings
Processing substitution for xml node : connectionStrings
Processing substitution for xml node : configSections
Skipped Updating file: ...\obj\Release\Package\PackageTmp\Web.config
Why web.config not getting updated with new value? Where I am doing mistake?

Related

How to edit variable in azure pipeline yaml file?

In the code below, the output of "echo ${{variables.myvariable}}" is always test.
I was expecting it to be test then uat.
How can I edit the variable value from the yaml file?
The format: ${{variables.myvariable}} will be expanded at compile time.
When you use command to update the variable, it will be updated at runtime.
This is the root cause of the issue.
I was expecting it to be test then uat. How can I edit the variable value from the yaml file?
To solve this issue, you need to modify the format to $(myvariable) or $[variables.myvariable]
For more detailed info, you can refer to this doc: Runtime expression syntax

Azure Devops Release Pipeline XML Variable Substitution not working

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!
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.
XML transformation will be run on the *.config file for transformation configuration files named *.Release.config or *.<stage>.config
https://learn.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.

File Transform task fails to transform XML configurations on zipped package

I'm working on Release pipeline, which will perform transformation on App Service Worker configs, then will publish workers + web application.
My input package is a zip package produced out of MsBuild publish (from ASP.NET build pipeline).
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\BillingWorker.exe.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\EtlWorker.exe.config
...\PackageTmp\Web.config
...\PackageTmp\Web.Test.config
...\PackageTmp\Web.Prod.config
...\PackageTmp\many other files
Transformation of Web.config is done correctly by Publish to Azure Web App task. However, workers configs aren't transformed automatically, so I added a File Transform task with following config:
This step doesn't work and here is the output:
2019-08-14T15:41:01.1435779Z ##[section]Starting: File Transform: config
2019-08-14T15:41:01.1576716Z ==============================================================================
2019-08-14T15:41:01.1576853Z Task : File transform
2019-08-14T15:41:01.1576932Z Description : Replace tokens with variable values in XML or JSON configuration files
2019-08-14T15:41:01.1576994Z Version : 1.156.0
2019-08-14T15:41:01.1600786Z Author : Microsoft Corporation
2019-08-14T15:41:01.1600885Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/file-transform
2019-08-14T15:41:01.1600986Z ==============================================================================
2019-08-14T15:41:01.6339900Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.6351367Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.8369297Z Initiated variable substitution in config file :
...
... many lines about variable subsitution
...
This output looks wrong, as it produces warning without declared explanation. How to workaround this warning?
The problem is that File Transform task strongly relies on names of both files - the one being transformed and the one containing transformation rules. Strict naming convention is required which can be described in following words:
A template named Name.xml can be transformed only by files named Name.Debug.xml, Name.Release.xml, and more general - Name.{anything-here}.xml.
What's happening here is that App.config file is renamed to {YourApplicationName}.exe.config during build thus the tranformation using App.Debug.config fails.
I see 2 workarounds:
1. Preserve the original name App.config
a. In a project file, set App.config file's property to Copy to output directory: Copy always
b. Setup "File Transform task" with args -transform *.Debug.config -xml *.config -result {YourApplicationName}.exe.config
c (optional). If you didn't specify -result in task, you need to setup another task to rename App.config to {YourApplicationName}.exe.config after the transformation has finished (for example a Command Line task with command copy App.config {YourApplicationName}.exe.config /Y)
2. Write custom transformator script
a. Unzip package into temp folder
b. Transform file using Powershell (make use of Microsoft.Web.XmlTransform.dll installed on agent)
c. Zip again and replace the original zip.
The native step in the official task doesn't support transformation in zip files. You can use another task for do it before the deploy task.
I used this and it worked fine to me:
https://marketplace.visualstudio.com/items?itemName=solidify-labs.vsts-task-tokenize-in-archive

Can we change the settings of the Windows applications app.config?

I have two app.config's in my application where i have written two connectionstrings in one config file and another two in other config file .Now in .cs file i have written this
string Connect = ConfigurationManager.ConnectionStrings["con1"].ConnectionString.ToString();
string Connect = ConfigurationManager.ConnectionStrings["con3"].ConnectionString.ToString();
Now first line gives the connectionstring from app.config.But for the second line am getting an error that "object reference not set to an instance"
Can any one tell me how to use the connection from different app.config's
Per Microsoft's documentation for the ConfigurationManager class, the ConnectionStrings property operates on the current application's default configuration file.
I believe that what you probably want to do is use the OpenExeConfiguration method to read the second app.config file then use the returned Configuration class instead of the static ConfigurationManager.

"Duplicate node detected" in a CruiseControl.NET configuration file

When I launch CruiseControl.NET with a particular configuration file I receive the following error:
ThoughtWorks.CruiseControl.Core.Config.ConfigurationException: Duplicate node detected
What does this mean, and what causes it?
I think you have 2 nodes in your config where it only expected one. Is there any chance you could post the config file it is throwing the exception on here as additional information? I'm using cruisecontrol (not the .net version) currently and find it can be very picky about it's XML files (rightly so) but not tell you anything about where in the file the exceptions were thrown from.
I found that I had an incorrectly structured config file. In particular, some blocks were outside of the configuration section. The error pointed to the second of these exec sections- apparently it didn't like that there was more than one of a given section inside the project.
Thus, the error occurred due a config file like this:
<project>
<tasks>
...
</tasks>
<exec>...</exec>
<exec>...</exec>
<project>
In my case I had something like:
<task>...</task>
<sourceControls>...</sourceControls>
<task>...</task>
<publishers>...</publishers>
It didn't like the two "<task>" nodes so I fixed it by removing the first "<task>" node. I was trying to do some stuff before getting the latest from svn, and then doing the build after that in the second "<task>" node. I'll need to revisit how to do that...any suggestions?

Resources