1
votes

I'm trying to use the task "File Transform" within my pipeline to modify a few values inside my web.config file during deployment.

I created the tasks as the following:

enter image description here

And in the pipeline, inside the variables, I set up the key & value that I want to replace in the XML file.

Everything seems to go fine, however, when I check the log, I see this

enter image description here

So, the file was simple skipped and the transformation didn't work.

The variable that I'm trying to modify in the web.config file has the following path inside the XML file

  <aspNetCore>
   <environmentVariables>
     <environmentVariable  name="x" value="y" />
    </environmentVariables>
   </aspNetCore>
 </configuration>

I read the documentation multiples times, but it's not clear if I'm doing something wrong.

Please, could you provide some suggestion of what I need to check to make it work?

Thank you

2
You can try to use replace token task or PowerShell scripts to make it work. You can refer to my samples:replace token task and PowerShell scriptsWalter
Glad to know your issue has been resolved. Please mark your answer. This will make it easier for people who have the same question to find answers.Walter

2 Answers

0
votes

According to the document about XML variable substitution:Variable substitution takes effect only on the applicationSettings, appSettings, connectionStrings, and configSections elements of configuration files. It does not apply to your environmentVariable element. It worked well on my side when I change value in appSettings element.

Please refer to the samples in the document about file transform.

0
votes

I'm answering my own question.

Based on the comments that I received, the solution that I found was the following:

1- Use Replace Token Task (https://github.com/qetza/vsts-replacetokens-task#readme) in the pipeline AFTER the deployment. I also removed that "File Transform", since it wouldn't work for what I needed. 2- In the configuration, I pointed the root folder to the deployed application, no the Zip file, as instructed by this other question (Azure Dev ops replace tokens per environment in release pipeline) 3- In the web.config file, I used the token prefix and suffix, as suggested "#{token}# 4- Added the variables to the variable groups

After deploying, I checked that it worked fine.