Transforming custom Xml configuration files during build

Jul 6, 2012 at 4:39 PM
Edited Jul 6, 2012 at 4:45 PM


I've done a little reading and it seems like MSBuild EP is the way to go if we want to transform our custom Xml configuration files during build. The following is an excerpt from:


<!-- Transform an Xml file with an Xslt file -->
<MSBuild.ExtensionPack.Xml.XmlTask TaskAction="Transform" XmlFile="C:\Demo1\XmlForTransform.xml" XslTransformFile="C:\Demo1\Transform.xslt">
<Output PropertyName="Out" TaskParameter="Output"/>


We don't necessarily have Xsd for our Xml; our configurations are basically C# class-driven entities, so the definition can change in an instant, makes less sense to maintain Xsd on top of the Xml.

That said, I take it with this example, we can target portions of our Xml with Xsl in order to transform only what we want transformed during a build process?

I'm less familiar with Xsl than I am with Xml or the serialization process at this point; are there any good examples that expose the Xsl we would need to transform the Xml?

Edit: Actually, and then there's the matter of, how does one specify MSBuild compile-time macros like $(SolutionDir) or $(TargetPath) (or whatever) to update values in the Xml: which is effectively what we want to do.

A poor-man's solution would be to conduct a "simple" Regex replace (also using EP) on the file(s) in question. We're doing that in places, but it'd be nice if we can stay closer to the Xml itself.


Aug 14, 2012 at 8:57 PM


The task operates over the whole xml file, but you can restrict what is transformed using your xslt.

I'm not following what you want to do with MSBuild properties... can you give me a scenario walk-through?

Sorry for the delay !