Web.config 转换:未声明转换属性

Web.config Transformation: Transform attribute is not declared

我正在尝试转换我的 Web.config 文件以添加发布版本的重写规则,但我收到智能感知错误。

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

Web.Release.config

似乎编译没问题。但是当我尝试发布时,我确实遇到了构建错误:

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

上面第一行是错误,第二行是警告。为什么这行不通?

请注意,我的 Web.config 的顶部包含行 <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

更新:

部署时的构建错误原来是由其他原因引起的。所以,事实上,它 确实 构建正常,我可以部署。所以在这一点上,问题就是为什么会出现这个 Intellisense error/warning。

正如 How do I enable IntelliSense in VS 2013 for <rewrite> in transform .config? 中所建议的,这是 Intellisense 中的一个缺陷。如果您使用的是 VS 2017 打开 "C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Xml\Schemas33\DotNetConfig.xsd"。找到文件末尾附近的重写元素并将 <xs:anyAttribute namespace="http://schemas.microsoft.com/XML-Document-Transform" processContents="strict"/> 复制到重写元素的末尾。 我一保存文件 Visual Studio 就删除了波浪形的警告。

可能有人应该向 Visual Studio 团队提出这个问题。