Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

TFS Build / Release Configuration Utilities: Edit app.config, web.config, appsettings.json, and XML


When you’re working automated builds and automated releases, you frequently need to edit configuration files like app.config, web.config, and appsettings.json. Well, I wrote a command line utility to do this and I figured I’d share.  I’ve got a version that is an .exe that can be used on a Windows build agent and I’ve got a version that’s written with .NET Core and can run cross-platform.  Both of them have the same commands.

Here are the commands:

getappsetting:
gets a value from <appSettings> in app.config or web.config

setappsetting:
sets a value in <appSettings> in app.config or web.config

replacetoken:
does a string replace in a file and replaces all occurences of a token (example: %%CONNECTIONSTRING%%) with an actual value

getconnectionstring:
gets a connection string value from app.config or web.config

setconnectionstring:
sets a connection string value in app.config or web.config

setjsonvalue:
sets a value in a json file such as appsettings.json

setxmlattribute:
locates an element in an XML file and sets an attribute value on that element

Here are the downloads:
Source code
EXE version for Windows
Cross-platform Binaries for .NET Core

I hope that these are helpful.

-Ben

— Want to do cross-platform or Azure DevOps with ASP.NET Core and TFS? Need some help automatically deploying Entity Framework or Entity Framework Core migrations from your TFS Builds and TFS Releases? Not quite sure where to start? We can help. Drop us a line at info@benday.com

SUBSCRIBE TO THE BLOG


One response to “TFS Build / Release Configuration Utilities: Edit app.config, web.config, appsettings.json, and XML”

  1. Irfan Charania Avatar

    Hi Ben,

    Thanks for putting out this awesome utility!

    I’m using it to update the appsettings.json out of our on-prem TFS 2018 release (the Web App Deploy task available for on-prem doesn’t have json variable substitution).

    I did notice one issue: The TFS commandline task does not fail when it encounters an error even if “Fail on Standard Error” is checked. It marks the task as “successful” even though it shows the error on the log.

    This can be easily fixed by changing line 63 in Benday.BuildUtilities\program.cs (and similar in .NET Core). Change from
    Console.Writeline
    to
    Console.Error.Writeline

    And then the TFS task fails as expected when it can’t find the file for example.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.