Update AppSettings with XmlUpdate in build scripts

Posted by Marcus Hammarberg on January 20, 2009
Stats

I know I will chase this one for ever if I don't put it up here...

We ran into a situation where we needed to tweak the AppSettings-section of an configuration before tests in the build script.

Luckily there is help to be found. With the XmlUpdate-task (in the MSBuild Community Tasks) this can be accomplished. IF you know how to write the XPath-query.

Here is how (found it here):

<XmlUpdate
   Namespace="http://schemas.microsoft.com/.NetConfiguration/v2.0"
   XmlFileName="$(SourceDir)\Core\ABSuite\ABClient\App.config"
   Xpath="//configuration/appSettings/add[@key='Main.ConnectionString']/@value"
   Value="$(DatabaseConnectionString)"
  />

Also here is a great site to pick up some XPath-skills.



Published by Marcus Hammarberg on Last updated