Alex Gordon
Alex Gordon

Reputation: 60841

How to replace values in app.config file during release?

I'd like to replace the value of Interval with variables from my release.

Here's my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="Interval" value="15000" />
    </appSettings>
</configuration>

I'm using Azure App Service Deploy task to deploy a .NET Core web job:

enter image description here

Here are all the options I have:

enter image description here

How do I replace values in my app.config using variables from my release?

Upvotes: 0

Views: 111

Answers (1)

Suresh Chikkam
Suresh Chikkam

Reputation: 3448

Thanks to @Levi Lu-MSFT for the Insight. In Azure DevOps release pipeline go to Pipeline > Variables add a variable with the name Interval and value 30000.

enter image description here

  • In the Azure App Service Deploy task go to the File Transforms & Variable Substitution Options section. Check the XML variable substitution checkbox.

Check that the app.config file is part of the deployment package and located in the correct folder.

  • The XML variable substitution feature will look for <add key="Interval" value="15000" /> in the app.config file.
  • It will replace the value="15000" with value="30000", based on the pipeline variable.

After deployment, transformed app.config file will look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="Interval" value="30000" />
    </appSettings>
</configuration>

Upvotes: -1

Related Questions