如何解决“无法find元素/属性<xxx>的模式信息?

在Visual Studio中,我有一个使用MS Enterprise Library 4.0应用程序块的asp.net 3.5项目。

当我打开我的Webconfiguration文件时,我的错误列表中填充了99条消息

Could not find schema information for the element 'dataConfiguration'. Could not find schema information for the attribute 'defaultDatabase'. Could not find schema information for the element 'loggingConfiguration'. Could not find schema information for the attribute 'tracingEnabled'. Could not find schema information for the attribute 'defaultCategory'. 

如果我closures了Web.config文件,它们就会消失(但是当我需要再次打开文件时它们会立即返回)。

在做了一些观察之后,我发现这是因为缺lessVisual Studio需要的XSD或模式文件才能正确“理解”web.config文件中的模式并为其提供智能感知。

有谁知道如何向VS提供适当的模式信息,或者closures这些消息?

@Franci – 感谢您的信息,我已经尝试过这个工具以及MMCpipe理单元(他们往往炸毁Web.config中的格式),但他们仍然不能解决我收到的恼人的警告。 感谢您的尝试。

我使用EntLibconfiguration工具configuration了app.config,并设置了我的LoggingConfiguration块。 然后我复制到DotNetConfig.xsd。 当然,它并不包含所有属性,只包含我添加的属性,但不会再显示那些恼人的信息消息。

 <xs:element name="loggingConfiguration"> <xs:complexType> <xs:sequence> <xs:element name="listeners"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="add"> <xs:complexType> <xs:attribute name="fileName" type="xs:string" use="required" /> <xs:attribute name="footer" type="xs:string" use="required" /> <xs:attribute name="formatter" type="xs:string" use="required" /> <xs:attribute name="header" type="xs:string" use="required" /> <xs:attribute name="rollFileExistsBehavior" type="xs:string" use="required" /> <xs:attribute name="rollInterval" type="xs:string" use="required" /> <xs:attribute name="rollSizeKB" type="xs:unsignedByte" use="required" /> <xs:attribute name="timeStampPattern" type="xs:string" use="required" /> <xs:attribute name="listenerDataType" type="xs:string" use="required" /> <xs:attribute name="traceOutputOptions" type="xs:string" use="required" /> <xs:attribute name="filter" type="xs:string" use="required" /> <xs:attribute name="type" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="formatters"> <xs:complexType> <xs:sequence> <xs:element name="add"> <xs:complexType> <xs:attribute name="template" type="xs:string" use="required" /> <xs:attribute name="type" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="logFilters"> <xs:complexType> <xs:sequence> <xs:element name="add"> <xs:complexType> <xs:attribute name="enabled" type="xs:boolean" use="required" /> <xs:attribute name="type" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="categorySources"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="add"> <xs:complexType> <xs:sequence> <xs:element name="listeners"> <xs:complexType> <xs:sequence> <xs:element name="add"> <xs:complexType> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="switchValue" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="specialSources"> <xs:complexType> <xs:sequence> <xs:element name="allEvents"> <xs:complexType> <xs:attribute name="switchValue" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> <xs:element name="notProcessed"> <xs:complexType> <xs:attribute name="switchValue" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> <xs:element name="errors"> <xs:complexType> <xs:sequence> <xs:element name="listeners"> <xs:complexType> <xs:sequence> <xs:element name="add"> <xs:complexType> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="switchValue" type="xs:string" use="required" /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="name" type="xs:string" use="required" /> <xs:attribute name="tracingEnabled" type="xs:boolean" use="required" /> <xs:attribute name="defaultCategory" type="xs:string" use="required" /> <xs:attribute name="logWarningsWhenNoCategoriesMatch" type="xs:boolean" use="required" /> </xs:complexType> </xs:element> 

我已经创build了一个新的scheme基于我目前的app.config消息消失。 我只是在Visual Studio中使用了“Create Schema”button,并为我创build了一个xsd模式。

将模式保存在适当的位置,并查看其中存在名为模式的属性的app.config文件的“属性”选项卡。 如果您单击更改button,则可以select使用原始的dotnetconfig模式和您自己的新创build的模式。

一个XSD包含在EntLib 5中,并安装在Visual Studio架构目录中。 就我而言,可以在下面find:

“C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Xml \ Schemas \ EnterpriseLibrary.Configuration.xsd”

CONTEXT

  • Visual Studio 2010
  • 企业图书馆5

删除警告的步骤

  1. 在Visual Studio项目中打开app.config
  2. 右键单击XML文档编辑器,select“属性”
  3. 将完全限定的path添加到“EnterpriseLibrary.Configuration.xsd”

在旁边

值得重复的是,这些“错误列表”“消息”(“无法find该元素的架构信息”)只有在打开app.config文件时才可见。 如果你“closures所有文件”并编译…没有消息将被报告。

您是否尝试过将模式文件复制到VS的XML模式caching文件夹? 您可以通过查看VS工具/选项/testing编辑器/ XML /杂项find该文件夹​​的位置。 不幸的是,我不知道MS Enterprise Library 4.0的模式文件在哪里。

更新 :安装MS企业库后,似乎没有.xsd文件。 但是,有一个编辑configuration的工具 – EntLibConfig.exe,您可以使用它来编辑configuration文件。 此外,如果你添加适当的configuration部分到你的configuration文件,VS应该能够正确parsingconfiguration文件。 (EntLibConfig会为你添加这些,或者你可以自己添加它们)。 以下是loggingConfiguration部分的示例:

 <configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> 

您还需要在项目中添加对相应组件的引用。

什么解决了“无法find元素的模式信息…”对我来说是

  • 打开我的app.config
  • 在编辑器窗口中右键单击并select“ Properties
  • 在属性框中,有一个名为Schemas的行,我单击该行并select行中出现的浏览...框。
  • 我简单地检查了我的项目在其中的所有行的use框,以及我使用的当前版本的.Net。 例如: DotNetConfig30.xsd

之后,一切正常工作。

我的项目中的这些模式行如何得不到控制我不确定,但是当我确定他们被检查了之后,我又恢复了业务。

导航到: NLog xsd文件

为您的项目下载相应的xsd并将其保存在NLog.config中

第一个为我做了诡计。