Using msbuild to change App.config and Web.config files

Using the msbuild community tasks project it becomes easy to change App.config and Web.config files as part of the build process. I've recently implemented a build script for a smart client application that allows building in multiple locations connecting to different application servers.

First, download the msbuild community tasks project. You can get this from subversion using the following command:

svn checkout msbuildtasks --username guest

Check the project out, build it and transfer the library and the.targets file to the desired directory. You can then import all of the tasks and start using the XmlUpdate task.

In order to work with App.config and Web.config you must add the appropriate namespace and reference the nodes in the xpath based on a custom-defined prefix. Here is a sample of this task in action: 

                         
This article is part of the GWB Archives. Original Author: Paul Whitaker

New on Geeks with Blogs