How do I make an extension xsd for the web/app.config schema?(如何为 web/app.config 架构制作扩展 xsd?)
问题描述
如何为自定义配置部分创建架构?我尝试制作一个,但当我使用它时,它说唯一预期的元素是我在该架构中拥有的元素,并抱怨标准的 web.config 东西,即使我仍在使用普通的 DotNetConfig.xsd 文件也是如此.
我发现的这个问题不是重复的,但是解决方案会解决你的问题:
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="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>
My schema file is in my project root, right next to app.config, and called NLog.xsd
. I simply saved it from here:
- http://nlog-project.org/schemas/NLog.xsd
这篇关于如何为 web/app.config 架构制作扩展 xsd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 web/app.config 架构制作扩展 xsd?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01