如何为web / app.config模式创建扩展xsd?

编程入门 行业动态 更新时间:2024-10-26 18:23:04
本文介绍了如何为web / app.config模式创建扩展xsd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何为自定义配置节创建模式?我试过做一个,但是当我使用它,它说只有预期的元素是我在那个模式,并抱怨标准web.config的东西,虽然我仍然使用正常的DotNetConfig.xsd文件。 / p>

解决方案

这个问题我发现并不重复,但解决方案会解决你的问题:

How do I make a schema for custom config sections? I tried making one, but when I used it, it said the only expected element was what I had in that schema, and complained about the standard web.config stuff, even though I was still using the normal DotNetConfig.xsd file too.

解决方案

This question I found isn't duplicate, but the solution will solve your problem:

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

The trick is to get the "Properties" of the app.config editor, and set the Schemas value:

  • Right Click -> Properties anywhere in the XML file editor, or just hit F4 while it is in focus
  • In that dialog, add a local or absolute reference to a schema file

My app.config file's properties window/gadget looks like this:

Here's an example I just got working (I'm toying around with Ninject and NLog). The elements and attributes under the nlog section show up correctly in Intellisense, and I get squiggly lines if I violate the schema.

<?xml version="1.0"?> <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> </configSections> <nlog xmlns="www.nlog-project/schemas/NLog.xsd" xmlns:xsi="www.w3/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>

My schema file is in my project root, right next to app.config, and called NLog.xsd. I simply saved it from here:

  • nlog-project/schemas/NLog.xsd

更多推荐

如何为web / app.config模式创建扩展xsd?

本文发布于:2023-11-04 00:40:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   模式   web   app   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!