Web.config transformation: Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive
Solution 1
I ran into the very same problem. You will find lots of banter out there related to MvcBuildViews and various error conditions. But none seem to mention this particular error. A quick fix that worked for me was to delete the contents of the "obj" directory for the affected web project, then rebuild.
Solution 2
This is kind of a workaround, but you may add the following line to your pre-build commands:
del $(ProjectDir)obj\* /F /S /Q
Right click your project > Properties > Build Events > Pre-build
Solution 3
This works with Continuous Integration and WebDeploy:
This problem occurs the moment I set
<MvcBuildViews>true</MvcBuildViews>
in my Project file, which I need to do.
After reading and testing everything I found about this problem I have a wokraround, that also works with WebDeploy via MSBuild
MSBUild.exe ... /p:DeployOnBuild=true
You (only) need to delete the TransformWebConfig subfolder in your buildfolder during the pre- AND post-build events. It even works with continuous integration servers which break if no folder exists
Pre-build event command line:
if exist "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\" del "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\*" /F /S /Q
Post-build event command line:
if exist "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\" del "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\*" /F /S /Q
This even works fine with Resharper
which will sometimes get confused, if you delete the whole obj
folder.
Make sure to set the Run the post-build event
to always
!!
UPDATE: Replaced debug and release with $(ConfigurationName) and removed resulting duplicate line
Solution 4
I resolve my conflict by doing the same thing that Job said. Removing the attribute
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
From the main Web.config and leave it into the Web.debug.config and Web.release.config
Solution 5
just remove the xmlns:xdt attribute from the web.config, but keep it in web.release.config and web.debug.config.
Your transform will still work - and so will your website.
Related videos on Youtube
Andrew Harry
I have been a web developer for the nearly n years. I have a background in graphic design and programming. I program in C# and VB. I can handle most DBA tasks. I prefer ASP.net MVC Personal blog
Updated on July 09, 2022Comments
-
Andrew Harry almost 2 years
I'm getting this strange intermitent bug in a MVC 3.0 project When I build the project sometimes I get the following error message:
Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive.
This is referring to the standard web.config tranformation file (Web.Release.config copied below) There are no other errors or warnings. This is happening in debug mode and release. Sometimes it clears if I clean the solution
BEGIN UPDATE
Found the issue. In the MVC Project file (MyProject.csproj) I had set build views to true
<MvcBuildViews>true</MvcBuildViews>
Once put back to false the above error goes away. I'd like to have the view build as it stops alot of stupid view code errors etc and is a performance enhancement (pages are precompiled instead of jit)
Anyone know what this is causing the error? is this a bug?
END UPDATE
<?xml version="1.0"?> <!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an atrribute "name" that has a value of "MyDB". <connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> <!-- In the example below, the "Replace" transform will replace the entire <customErrors> section of your Web.config file. Note that because there is only one customErrors section under the <system.web> node, there is no need to use the "xdt:Locator" attribute. <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> --> </system.web> </configuration>
-
Andrew Harry over 11 yearsThe web.release.config above is exactly as provided by MS
-
usr-local-ΕΨΗΕΛΩΝ about 11 yearsI had never touched MvcBuildViews and it defaults to false. This error appeared all of a sudden
-
Andre Calil almost 11 years@AndrewHarry it would be nice to mark one of the answers as correct, after all this time =)
-
Andrew Harry over 10 years@AndreCalil I would mark one as the 'Answer' but as you say it was a long time ago and I wouldn't have a clue which is the best
-
Andrew Harry over 10 yearsAlso I'm not getting this error now so i'm guessing it was a bug which subsequent updates to the framework have now fixed?
-
Andre Calil over 10 years@AndrewHarry I'm not sure, but selecting on of the answers would be somewhat polite, you know?
-
Yishai Galatzer over 9 years@AndrewHarry note that you assume that MvcBuildViews prevents "jitting" (or code gen + compilation + jitting really) on the server. Note that it actually does not do any of these things. It only helps validate your build. See this thread - stackoverflow.com/questions/383192/compile-views-in-asp-net-mvc
-
Andrew Harry over 8 years@YishaiGalatzer Cheers for pointing that out!
-
-
Mathias Lykkegaard Lorenzen about 11 yearsRemember to wrap quotes around the
$(ProjectDir)obj\*
part if your project is located in a path that has spaces in it. -
Andre Calil about 11 years@MathiasLykkegaardLorenzen Yes, indeed. Thanks.
-
PhilW almost 11 years@AndreCalil No, not me.
-
Andre Calil almost 11 yearsNevermind, so. Some guy simply downvoted without telling me why. Go figure!
-
Anderson Pimentel over 10 yearsGood one. I was about to set MvcBuildViews to false against my will just to get rid of this error. Thanks!
-
Andre Calil over 10 years@gldraphael Thanks for the feedback, glad to help
-
beautifulcoder about 10 yearsBoy, I thought 'Clean Solution' meant exactly that. Guess I was wrong.
-
joelmdev almost 10 yearsI wish I had a full understanding of why this happens. When I was running my TeamCity server on my local machine everything worked fine. As soon as we moved TeamCity to a dedicated buildserver we started running into this issue. Perhaps it's worth starting an MS Connect issue for.
-
joelmdev almost 10 yearsI had to add this as a post build event as well to get things running
-
joelmdev almost 10 yearsConnect issue created here: connect.microsoft.com/VisualStudio/feedback/details/933625/…
-
roadsunknown about 9 yearsI've tried several solutions including the Pre/Post-build event command line. This seems to have only worked the first time, but subsequent builds keep failing. So far only MvcBuildViews=false seems to offer the most consistent fix, but will not be an acceptable workaround for every project.
-
hatsrumandcode over 8 yearsThis issue was pretty annoying, as it was not happening for every build. Thanks @AndreCalil doing what you suggested fixed that for me!
-
Andre Calil over 8 years@SlickShinobi thanks for the feedback, glad it helped
-
Andrew Harry over 8 yearsDeclaring this the winner
-
JeffFerguson almost 5 yearsNot working for me in VS 2019. I ran Clean solution, I deleted obj as well as bin, and ran Rebuild All.
-
HydTechie over 3 yearsYOU ARE THE SAVIOUR!.. HOW COME NOBODY USED THIS SOLUTION.. thanks a ton @JOB.. this worked in case of winforms, app.config - slowcheetah transformations!