我正在尝试转换我的Web.config文件以为发布版本添加重写规则,但出现了智能错误。


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


Web.Release.config

visual-studio - Web.config转换:未声明转换属性-LMLPHP

看起来可以编译,没有错误。但是,当我尝试发布时,确实出现了构建错误:


源文档中没有元素匹配“ /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错误/警告。

最佳答案

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

visual-studio - Web.config转换:未声明转换属性-LMLPHP

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

关于visual-studio - Web.config转换:未声明转换属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44294558/

10-13 08:06