I know I will chase this one forever if I don’t put it up here…
We encountered a situation where we needed to tweak the AppSettings
section of a configuration before running tests in the build script.
Luckily, there is a solution available. With the XmlUpdate
task (from the MSBuild Community Tasks), you can accomplish this—if you know how to write the XPath query.
Here’s how to use it (I found this example 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)" />
Additionally, if you need to brush up on your XPath skills, check out this XPath tutorial for some great examples.