2
votes

I’m fairly new to implementing CI/CD through Azure DevOps and I have what is probably a typical scenario that I’m not sure how to address. Most of the articles I’ve found dealing with file transformation deal with IIS Deploy but I’m currently working with .Net Framework console apps.

In my console apps we have certain settings, usually file paths, that are different based on the environment we are in (Dev, Stage, Prod) as well as the database connection string being different in each environment.

I was shown how to use variables, ex: __connectionstring__, that can be set and replaced in a Azure DevOps release pipeline using the Tokenizer app. However, having that variable in my development environment doesn’t work. When I debug in Visual Studio it still sees the above variable name and doesn’t have something like the tokenizer to populate that variable locally on my development machine.

Can someone point me to an article or example on a good way to have appsettings specific to each environment I’m in that will allow me to still debug locally but also change the settings in the ADO release pipeline?

2

2 Answers

5
votes

You can use task File transform to replace certain settings in Azure DevOps release pipeline.

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.

For example you have below appsetting.json file. And you want to change the default log level to Error.

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

1, First you need to define a Release Variable Logging.LogLevel.Default in the Variables section of the release pipeline edit page with the value Error assigned to it. See below

enter image description here

2, Add the File transform task in your release pipeline. enter image description here

For more information about XML variable substitution, please check it out here.

There are also third party substitution tools(ie. Magic Chunks/ RegEx Find & Replace ) that are very convenient to use to replace the values in your settings files in azure pipeline. Please check out the example in this thread.

0
votes

To transform .config files of non-web applications, I always use SlowCheetah:

It works just like the web.config transformation, but for app.config.