Update appsettings.json at deploy time with VSTS Release Management

Pieter Gheysens
Jul 27, 2017 · 3 min read

Lately I have to deal more with .NET Core Web Applications to setup build and release definitions in VSTS. What always comes up is how to deal with specific application settings which must me updated for a specific environment.

I have always been a big advocate of making a clear separation between build and release. The build should simply generate a generic package while the release should pick up the package and deploy it to any possible environment. At deployment time the specific enviroment values should be injected. Web Deploy has been the obvious tool in the past to make this happen with the capability to update the generated setparameters.xml file in a deployment action which injected the environment values into the web.config file.

Now with .NET Core and the typical appsettings.json file, it has become really easy in VSTS to inject custom values into the appsettings.json file.

Example of appsettings.json file in my solution:

AppSettings
AppSettings

Imagine that you would want to replace the values for the different settings (as from line 8). Note that it will also be possible to replace the values in the “Administrators” array.

First, you will need to create a build in VSTS which produces the deployment zip package (via dotnet publish command).

BuildOutput
BuildOutput

The VSTS release definition will link to the build output and you can use the built-in release task “Azure App Service Deploy” to deploy the build output to an Azure App Service.

ReleaseTask
ReleaseTask

The “File Transformation” section in the release task offers the possibility to define the JSON variable substitution. You will need to provide the file name from the root and the environment values (pay attention to the format of the variable names) can be set for the “DEV” environment.

Variables
Variables

Doing a file lookup from the console in the Azure Portal after deployment shows the result of the appsettings file.

image
image

Simple solutions are always the best solutions!

Into ALM

Blogging About Application Lifecycle Management with TFS/VSTS

    Pieter Gheysens

    Written by

    Visual Studio ALM MVP — Managing Director Xpirit Belgium (2018) — Founder of Techorama (2014) — www.techorama.be — www.xpirit.com

    Into ALM

    Into ALM

    Blogging About Application Lifecycle Management with TFS/VSTS

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade