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>

MSBuild - Non-string data for Inetstp@MajorVersion

When using the the Microsoft.Web.Publishing.Tasks.dll library to do the XML Transforms in a Continuous Integration set-up, like TeamCity. You receive an error like below:

[GetProjectWebProperties] error MSB4138: Non-string data was specified at the registry location "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Inetstp@MajorVersion".

If this is the case, ensure that your build scripts are using .NET 4.0. The scripts I had were defaulting to use .NET 3.5 which threw the error.