如何为web / app.config架构创建扩展xsd?

时间:2009-07-14 18:57:44

标签: .net configuration xsd

如何为自定义配置部分制作架构?我尝试制作一个,但是当我使用它时,它说唯一预期的元素是我在该模式中所拥有的,并抱怨标准的web.config内容,即使我仍然使用正常的DotNetConfig.xsd文件。 / p>

3 个答案:

答案 0 :(得分:36)

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

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

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

  • 右键点击 - > 属性在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。我只是从这里保存了它:

答案 1 :(得分:0)

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

让intellisense与新创建的app.config文件一起使用...

步骤1:将新项目App.Config添加到您的解决方案中。
它看起来像这样,请注意intellisense错误:

AppConfigs

步骤2:在编辑器中按F4以显示XML文档的Properites页面:

我的默认设置显示了这个:

Properties

第3步:点击上方Schemas属性最右侧的elipse ...

检查DonNetConfig.xsd,关闭窗口并开始输入

Intellisense

不再有错误和智能感知......

答案 2 :(得分:-1)

当我尝试这个时,它没有用。配置系统假定所有内容都在默认命名空间中,如果不是,则会发生阻塞。这非常令人失望。

相关问题