Avoid Unrecognized attribute 'xmlns:xdt' configuration error

If you've been using web.config transformations or a nuget package with transformations in at all you'll no doubt have come across the runtime configuration error of "Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive" pointing at the start of the <configuration> node (if not see below). This one has been bugging me for a while so I thought I'd work a way around it.

Server Error in '/' Application.

Configuration Error

Description:

Parser Error Message:

Source Error:

Line 1:  <?xml version="1.0" encoding="utf-8"?>
Line 2:  <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
Line 3:    <configSections>
Line 4:      <section name="Exceptioneer" type="Something, Assembly" requirePermission="true" />

Source File: c:\domain.com\web.config    Line: 2

Version Information:

The Solution

To work around this, I've assumed you're running some form of custom build already (or have access to add a pre-deploy build step).

  1. Download and install the MSBuild Community Tasks
  2. Add the new FileUpdate build step below which looks at your config file (you'll need to run this against each one). You'll also need to have a space in the ReplacementText as you can't currently replace with String.Empty.
  3. You're done

    <ItemGroup> <FileUpdateFiles Include="**\*.config" /> </ItemGroup> <FileUpdate Files="@(FileUpdateFiles)" Regex=" xmlns\:xdt\=&quot;http\://schemas\.microsoft\.com/XML-Document-Transform&quot;" ReplacementText=" " />

    If you've got a better (automated) solution, please let me know, it's been bugging me for ages!

    Subscribe to TSD

    Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
    jamie@example.com
    Subscribe