Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.config Transformation: Transform attribute is not declared

I am attempting to transform my Web.config file to add rewrite rules for release builds, but I'm getting an intellisense error.

The 'http://schemas.microsoft.com/XML-Document-Transform:Transform' attribute is not declared.

Web.Release.config

Web.Release.config

It seems to compile okay without errors. But when I attempt to Publish, I do get build errors:

No element in the source document matches '/configuration/system.webServer/rewrite'
The 'http://schemas.microsoft.com/XML-Document-Transform:Transform' attribute is not declared.

The first line above is an error, while the second one is a warning. Why doesn't this work?

Note that the top of my Web.config does include the line <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

UPDATE:

The build error when deploying turned out to be caused by something else. So, in fact, it does build okay and I can deploy. So at this point, the question is just about why this Intellisense error/warning is appearing.

like image 412
Jonathan Wood Avatar asked May 31 '17 20:05

Jonathan Wood


People also ask

What is xdt transform in web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.

How does web config transform work?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I rename a web config transform?

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project.


1 Answers

As suggested in How do I enable IntelliSense in VS 2013 for <rewrite> in transform .config? this is a defect in Intellisense. If you're using VS 2017 open "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Xml\Schemas\1033\DotNetConfig.xsd". Locate the rewrite element near the end of the file and copy <xs:anyAttribute namespace="http://schemas.microsoft.com/XML-Document-Transform" processContents="strict"/> to the end of the rewrite element. As soon as I saved the file Visual Studio removed the warning squiggly.

enter image description here

Someone should probably raise this with the Visual Studio team.

like image 136
Phil Avatar answered Oct 22 '22 18:10

Phil