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

Max*_*ing 20 .net configuration xsd

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

Mer*_*ham 37

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

如何修复错误:"无法通过创建架构找到属性/元素的架构信息"

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

  • 右键单击 - > 属性在XML文件编辑器中的任何位置,或者只是F4在它处于焦点时点击
  • 在该对话框中,添加对模式文件的本地或绝对引用

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

Visual Studio中的app.config文件的

这是我刚刚开始工作的一个例子(我正在使用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>
Run Code Online (Sandbox Code Playgroud)

我的架构文件位于我的项目根目录中,紧挨着app.config,并被调用NLog.xsd.我只是从这里保存它: