如何在 app.config 中获取自定义部分的智能感知? [英] How do I get intellisense in app.config for a custom section?

查看:26
本文介绍了如何在 app.config 中获取自定义部分的智能感知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的 app.config 文件中有一个与 IoC 容器类相关的自定义部分.如何在编辑本节的配置文件时获得智能感知,以及删除通知我缺少架构的编译器消息.

We have a custom section in my app.config file related to our IoC container class. How can I get intellisense when editing the config file for this section, as well as getting rid of the compiler messages informing me of the missing schema.

我在这里发现了这个问题:app.config configSections custom设置找不到架构信息,但我不明白它是否适用于我的问题,以及如何使用那里的答案.

I found this question here: app.config configSections custom settings can not find schema information, but I don't understand if it applies to my problem or not, and how to use the answer there if it does.

我也找到了这个页面 如何获取 Intellisense for Web.config 和 App.config在 Visual Studio .NET 中,但它说在运行应用程序之前删除 xmlns 属性.这真的是唯一/最好的方法吗?

I also found this page How to get Intellisense for Web.config and App.config in Visual Studio .NET, but it says to remove the xmlns attribute before running the application. Is that really the only/best way?

这是一个简单文件的例子:

Here is an example of a simple file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="ServiceContainers"
        type="LVK.IoC.RegistrationsSectionHandler, LVK"/>
  </configSections>
  <ServiceContainers>
    <Registration type="DatabaseConnection" class="DatabaseConnection">
      <Parameter name="connectionString" type="System.String"
          value="TYPE=MSSQL2000;SERVER=localhost;DATABASE=db"/>
    </Registration>
  </ServiceContainers>
</configuration>

基本上我希望能够在 <ServiceContainers> 节点内输入 <R,并在智能感知下拉列表中向我建议注册,以及作为它的适当属性.

Basically I would like to be able to type <R inside the <ServiceContainers> node, and get Registration suggested to me in the intellisense dropdown, as well as the appropriate attributes for it.

推荐答案

XML Intellisense 不会自动用于自定义配置部分.

XML Intellisense will not automatically work for a custom configuration section.

Visual Studio 可能会报告编译警告,抱怨未定义自定义配置部分的属性.这些警告可能会被忽略.

Visual Studio may report warnings on compilation complaining that the attributes of the custom configuration section are not defined. These warnings may be ignored.

如果您希望 XML IntelliSense 支持自定义配置部分(或者如果您只是希望找不到架构"警告消失),请在第一个 <xs:schema 之后立即将以下行添加到您的 DotNetConfig.xsd 文件中...>行(通常是 DotNetConfig.xsd 文件中的第二行).

If you want XML IntelliSense support for a custom configuration section (or if you just want the 'schema not found' warnings to disappear), add the following line to your DotNetConfig.xsd file immediately after the first <xs:schema ...> line (which is typically the second line in the DotNetConfig.xsd file).

<xs:include schemaLocation="YOUR_DIRECTORY\namespace.assemblyname.xsd"/>

DotNetConfig.xsd 文件位于 Xml\Schemas 子目录的 Visual Studio 8(或 9)安装目录中.

The DotNetConfig.xsd file can be found in your Visual Studio 8 (or 9) installation directory in the Xml\Schemas subdirectory.

这篇关于如何在 app.config 中获取自定义部分的智能感知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆