Azure DevOps File Transformation Pipeline

Azure DevOps. Build Pipelines and establishing build configurations when deploying to a Windows environment. The following is quick documentation walking through the process to ensure appropriate web.config files and transforms are performing during the publish steps within your pipeline. This is one approach used, while I believe there are still other alternatives available.

- May 28, 2020

Rest of the Story:

Running locally via Visual Studio and JetBrains Rider and managing the ASPNETCORE_ENVIRONMENT variable has been challenging.  Changing and setting ASPNETCORE_ENVIRONMENT within launchSettings.json and/or within Project Properties impacts the web.{envrionment}.config files.  Without the appropriate configuration within the publish steps the site was being deployed with incorrect settings and it was time consuming to track it back to the best approach.  So for now I have a pipeline build process setup for each AppService ‘slot’ setting different BuildConfiguration within each to ensure the most appropriate web.config is deployed.

This is a .net core web application so why the web.config? It appears that locally during IIS Express/IIS there is still a dependency on this web.config to identify the hosting model (inprocess) and reference to the exe that would be run.  This is of course when deploying to Windows infrastructure.
Project Properties – Environment variables


My launchSettings.json – you can see I can modify before running how IIS or IIS Express identifies the environment variable


The resultant/related web.configs looks like the following for Development and Staging environments.

web.config image
web.Staging.config (you can see the addition of the xdt:Transform=”Replace” attribute which informs publish that when building for Staging to replace this variable within web.config with this value) image

By default the build process on Azure DevOps – Pipelines was ignoring any file transformation requirements.  In order to establish File Transformation on publish notice the –configuration $(BuildConfiguration)

and the respective variable that is used during publish to identify the appropriate configuration to use (development/staging etc.) image

After the build and using App Service Editor my web.config was successfully transformed