在.config文件中启用自定义部分的智能感知

Kev*_*ock 38 .net configuration intellisense app-config web-config

在Visual Studio中编辑.NET配置文件(app.config,web.config等)时,我会选择Visual Studio的intellisense来指导我选择应用程序的设置.如果我添加自定义配置部分,如何为我的自定义设置启用intellisense?我确信必须有一个简单的答案,但粗略的谷歌搜索并没有给我任何帮助.

谢谢!

sta*_*ica 34

正如其他答案所说,您需要为自定义配置部分提供XML Schema文档.无需将.xsd模式文件添加到某个全局目录; 您可以直接从App.config文件中的自定义部分引用它:

<configuration>

  <!-- make the custom section known to .NET's configuration manager -->
  <configSections>
    <section name="customSection" type="..." />
  </configSections>

  <!-- your custom section -->
  <customSection xmlns="http://tempuri.org/customSection.xsd"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="customSection.xsd">
    ...
  </customSection>

<configuration>
Run Code Online (Sandbox Code Playgroud)

xmlns属性仅用于设置默认命名空间,因此您无需在customSection元素及其所有子元素上设置它.(但是,不要将xmlns属性放在<configuration>元素上!)

customSection.xsd包含将通过智能感知来使用,例如模式:

<xs:schema id="customSectionSchema"
           targetNamespace="http://tempuri.org/customSection.xsd"
           elementFormDefault="qualified"
           xmlns="http://tempuri.org/customSection.xsd"
           xmlns:mstns="http://tempuri.org/customSection.xsd"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="customSection">
    ...
  </xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)


Mic*_*tum 31

如果您不想修改Visual Studio文件或将任何内容复制到Visual Studio文件夹中,则可以将该.xsd文件添加到项目中,打开.config文件并在" 属性"窗口中选择" 架构 " (单击图标):[…]

Visual Studio的屏幕截图,显示在何处查找和更改<code> .config </ code>文件的

  • +1已接受的解决方案似乎已被广泛使用,但除非架构更改对于可能在您的计算机上创建的所有Visual Studio项目都是标准且有用,否则不应执行此操作.(http://msdn.microsoft.com/en -us /库/ ms255821.aspx) (5认同)

Jos*_*lio 11

您需要为自定义设置创建XSD文件,并将其复制到Visual Studio安装的架构目录中.对于2005年,这是:%ProgramFiles%\ Microsoft Visual Studio 8\XML\Schemas

这里有一些信息. http://blogs.msdn.com/astebner/archive/2005/12/07/501466.aspx