47

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

当我打开我的 web 配置文件时,我的错误列表充满了 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'.  

如果我关闭 Web.config 文件,它们就会消失(但只要我需要再次打开文件,它们就会回来)。

经过一番查看,我发现这是因为缺少 Visual Studio 需要的 XSD 或架构文件,以便正确“理解”web.config 文件中的架构并为其提供智能感知。

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

@Franci - 感谢您提供信息,我已经尝试过该工具以及 MMC 管理单元(它们往往会破坏 Web.config 中的格式),但它们仍然无法解决我收到的恼人警告。感谢您的尝试。

4

6 回答 6

31

我已经根据我当前的 app.config 创建了一个新方案,以使消息消失。我刚刚使用了 Visual Studio 中显示“创建架构”的按钮,并为我创建了一个 xsd 架构。

将架构保存在适当的位置,然后查看 app.config 文件的“属性”选项卡,其中有一个名为 Schemas 的属性。如果单击此处的更改按钮,您可以选择同时使用原始 dotnetconfig 架构和您自己新创建的架构。

于 2009-01-21T09:06:37.363 回答
13

XSD 包含在 EntLib 5 中,并安装在 Visual Studio 架构目录中。就我而言,它可以在以下位置找到:

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

语境

  • 视觉工作室 2010
  • 企业图书馆 5

删除警告的步骤

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

在旁边

值得重申的是,这些“错误列表”“消息”(“找不到元素的架构信息”)仅在您打开 app.config 文件时可见。如果您“关闭所有文档”并编译...不会报告任何消息。

于 2011-09-22T15:34:06.720 回答
11

app.config使用 EntLib 配置工具进行了配置并设置了我的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>
于 2009-01-21T09:45:10.950 回答
1

您是否尝试将架构文件复制到 VS 的 XML 架构缓存文件夹?您可以通过查看 VS Tools/Options/Test Editor/XML/Miscellaneous 找到该文件夹​​的位置。不幸的是,我不知道 MS Enterprise Library 4.0 的架构文件在哪里。

更新:安装 MS 企业库后,似乎没有 .xsd 文件。但是,有一个用于编辑配置的工具 - EntLibConfig.exe,您可以使用它来编辑配置文件。此外,如果您将正确的配置部分添加到配置文件中,VS 应该能够正确解析配置文件。(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>

您还需要在项目中添加对相应程序集的引用。

于 2008-10-07T19:24:54.183 回答
1

对我来说,解决“找不到元素的架构信息......”的问题是

  • 打开我的app.config.
  • 在编辑器窗口中单击鼠标右键并选择Properties.
  • 在属性框中,有一个名为 的行Schemas,我单击了该行并选择了...该行中出现的浏览框。
  • 我只是选中了use包含我的项目的所有行的框,以及我正在使用的当前版本的 .Net。例如:DotNetConfig30.xsd

之后,一切都正常工作。

我不确定我的项目中的那些模式行是如何被取消选中的,但是当我确保它们被选中时,我又重新开始工作了。

于 2015-03-28T19:15:14.373 回答
0

导航到此:NLog xsd 文件

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

第一个为我做了伎俩。

于 2014-07-04T13:27:56.430 回答