Monday, 12 December 2011

MSBuild and XmlTransform

Using .NET 4.0 you can use the Config Transformation features by which we can maintain multiple configuration files for different environments. To have one of these files built as part of your continuous integration you can use the MSBuild task TransformXml:

An example of the code usage is below:

<UsingTask TaskName="TransformXml" 
           AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

<Target Name="GenerateConfigs">
  <TransformXml Source="Source\Web.config"
                Transform="Source\Web.$(Configuration).config"
                Destination="Output\Web.config"/>
</Target>

No comments: