代码之家  ›  专栏  ›  技术社区  ›  Max Schmeling

如何为web/app.config架构生成扩展xsd?

  •  19
  • Max Schmeling  · 技术社区  · 15 年前

    如何为自定义配置节创建架构?我试着做了一个,但是当我使用它时,它说唯一期望的元素是我在那个模式中所拥有的,并且抱怨标准web.config的东西,即使我仍然在使用普通的dotnetconfig.xsd文件。

    3 回复  |  直到 15 年前
        1
  •  36
  •   Community basarat    7 年前

    我发现的这个问题不是重复的,但解决方法可以解决您的问题:

    How to fix Error: "Could not find schema information for the attribute/element" by creating schema

    诀窍是获取app.config编辑器的“属性”,并设置 Schemas 价值观:

    • 右击 -gt; 性质 在XML文件编辑器中的任何位置,或者只点击 F4 当它聚焦的时候
    • 在该对话框中,添加对架构文件的本地或绝对引用

    我的app.config文件的属性窗口/小工具如下:

    Properties dialog in Visual Studio for the app.config file

    举个例子我 只是 开始工作(我在玩弄Ninject和Nlog)。下的元素和属性 nlog 节在intellisense中正确显示,如果我违反了模式,我会得到歪斜的行。

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
      </configSections>
      <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <targets>
          <target name="eventLog" xsi:type="EventLog" log="Application"
                  category="TestService" />
          <target name="file" xsi:type="File"
                  layout="${longdate}|${stacktrace}|${message}"
                  fileName="${logger}.txt" />
        </targets>
        <rules>
          <logger name="*" minlevel="Info" writeTo="eventLog" />
          <logger name="*" minlevel="Debug" writeTo="file"/>
        </rules>
      </nlog>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
      </startup>
    </configuration>
    

    我的架构文件在我的项目根目录中,就在app.config旁边,并调用 NLog.xsd . 我只是把它从这里保存了下来:

        2
  •  0
  •   JWP    8 年前

    也许只是我的环境或是.NET 4.6中的一些变化(不确定)。

    要让IntelliSense使用新创建的app.config文件…

    步骤1:将新的item app.config添加到解决方案中。
    它将如下所示,请注意IntelliSense错误:

    AppConfigs

    第2步:在编辑器中按F4键显示XML文档的属性页:

    我的默认值显示如下:

    Properties

    步骤3:单击上面schemas属性最右边的elipse…

    检查donnetconfig.xsd,关闭窗口并开始键入

    Intellisense

    不再有错误和IntelliSense工作…

        3
  •  -1
  •   John Saunders    15 年前

    我试过的时候,它不起作用。配置系统假定所有内容都在默认名称空间中,如果不在,则阻塞。真令人失望。