• Max Morrow

Azure DevOps YAML Pipelines: Configuration Transformation in .NET Core Projects

Updated: Dec 29, 2021

There are a bunch of different methods you can use to perform configuration transformation in .NET Core. Let's go through one option available for transforming your app config at the time of release.


If you're not using configuration transformation, and you're still storing your environment configuration within your appsettings.env.json files in source control, I'd strongly recommend you start the process of moving that configuration into encrypted values in Variable Groups or Azure Key Vault.


Appsettings.json Transformation: Using Variable Groups

This method is very flexible, which is why it's my recommended approach, especially for teams that are templating their config transformation across deployments to multiple platforms/technology. You can use this method regardless of which platform you're deploying to.

  1. Install the Replace Tokens extension within Azure DevOps, it's going to perform most of the work.

  2. Head to Variable Groups within your Azure DevOps project and create a new Variable Group:

3. Save your variable name, we'll use it when you modify your appsettings.json

4. Head to your Visual Studio Solution and open your appsettings.json

5. Update the setting(s) that you'd like to replace in the pipeline to be ${Your_Variable}

6. Add your Variable Group to your pipeline in the variables: section of your stage:


- stage: publish_docker_image

variables: - group: "Your_Variable_Group"


7. Open your YAML Release pipeline and add the following:


- task: qetza.replacetokens.replacetokens-task.replacetokens@3 displayName: "Build: Replace Tokens" inputs: targetFiles: **/appsettings.json tokenPrefix: "${" tokenSuffix: "}"


8. Finished! Run your pipeline!


Bonus: Troubleshooting

The plugin we're using in this example makes it extraordinarily easy to troubleshoot your variable group substitution at release time. If you head to the "Build: Replace Tokens" stage and take a look at the log output it will tell you:

  • If it found the file(s) you're attempting to perform a replace on

  • How many tokens it found to replace

  • If any tokens were not replaced, and what their names were

787 views0 comments