0121 31 45 374
Qoute Icon

Avoid Unrecognized attribute 'xmlns:xdt' configuration error

Tim

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: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive.
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: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

 

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
    Simple but effective I think Smile
<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!

Liked this post? Got a suggestion? Leave a comment