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

18

我试图转换我的 Web.config 文件,为发布版本添加重写规则,但是我遇到了 IntelliSense 错误。

'http://schemas.microsoft.com/XML-Document-Transform:Transform' 属性未声明。

Web.Release.config

Web.Release.config

它似乎能够编译通过而没有错误。但是在我尝试发布时,确实出现了构建错误:

源文档中没有元素与“/configuration/system.webServer/rewrite”匹配
http://schemas.microsoft.com/XML-Document-Transform:Transform”属性未声明。

以上第一行是一个错误,第二行是一个警告。为什么这样做不起作用呢?

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

更新:

部署时的构建错误实际上是由其他原因引起的。所以,实际上,它能够编译通过并且我可以发布。所以现在,这个问题只关于为什么出现 IntelliSense 错误/警告。


你尝试过在进行rewrite之前使用<add xdt:Transform="RemoveAll" />吗?否则,进入XML菜单,选择schemas并查找DotNetConfig.xsd,然后选择使用此模式。如果仍然无法正常工作,您还可以尝试选择RazorCustomSchema.xsdEntityFrameworkConfig_6_1_0.xsd模式。如果现在仍然无法正常工作,请在配置中将链接设置为:xmlns="http://schemas.microsoft.com/XML-Document-Transform"。此外,如果您在浏览器中使用该链接,则会看到“您正在查找的资源已被删除、名称已更改或暂时不可用。”。 - King Reload
嗨@Jonathan。恐怕我没有答案,但似乎这个问题以前已经被问过了。https://dev59.com/SIDba4cB1Zd3GeqPDVwC - Rob
你也可以尝试在configuration中添加<configSections><connectionStrings> - King Reload
似乎Intellisense存在缺陷。请参见https://dev59.com/SIDba4cB1Zd3GeqPDVwC。 - Phil
@Muflix:没有什么需要解决的。这是Intellisense的问题。除了红色波浪线之外,它仍然按预期工作。 - Jonathan Wood
显示剩余2条评论
1个回答

21

如何在transform .config中启用VS 2013中的 IntelliSense <rewrite>所建议的,这是Intellisense中的缺陷。

  • 如果您使用的是VS 2017,请打开“C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Xml\Schemas\1033\DotNetConfig.xsd”。

  • 在文件末尾附近找到xs:element name="rewrite"元素并复制

    <xs:anyAttribute namespace="http://schemas.microsoft.com/XML-Document-Transform" processContents="strict"/>
    

    到重写元素的末尾。

我一保存文件,Visual Studio 就消除了警告下划线。

enter image description here

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


5
我已经通过Visual Studio反馈提出了这个问题。https://developercommunity.visualstudio.com/content/problem/67412/intellisense-issue-rewrite-transform.html - Phil
12
在Visual Studio 2019中似乎仍然存在这个问题,但修复方法并没有解决它。 - Neo
@Neo:你能解决上述的问题吗? - user527614
@user527614 我不记得了,因为我已经有一段时间没有再处理 Web.config 文件了。 - Neo
1
也出现在 VS 2022 中 - Jon Koivula

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接