01 Mar 2013
MSBuild Community Tasks XmlRead and XmlUpdate
Importing the MSBuild Community Tasks into a Visual Studio project can make difficult tasks easy. In my scenario I wanted to hook into the BeforeBuild target so I could modify the defaultVersion attribute in a combres.xml before TeamCity created a Release build.
Firstly you need to import the MSBuild Community Tasks (MSBCT) into the .csproj. And in my scenario I didn’t want other developers to have to install MSBCT so I conditionally import on non-debug builds.
Then I wanted to prove the concept so I used XmlRead first. I had to workout the XPath first, so once that was defined I dropped that into the XPath attribute:
Running from the command line: <pre>msbuild.exe project.csproj /t:BeforeBuild /p:configuraton=Release</pre> I could see the output of XmlRead on the command line.
Switching to XmlUpdate now made sense. So I commented out the XmlRead and added
Now the combres.xml file has it’s defaultVersion attibute modified for every Release build.
Til next time,
Ben at 08:50