在 Visual Studio 中编辑 .NET 配置文件(app.config、web.config 等)时,我得到 Visual Studio 的智能感知来指导我选择应用程序的设置。如果我添加自定义配置部分,如何为我的自定义设置启用智能感知?我相信这个问题一定有一个简单的答案,但粗略的谷歌搜索并没有给我任何帮助。
谢谢!
在 Visual Studio 中编辑 .NET 配置文件(app.config、web.config 等)时,我得到 Visual Studio 的智能感知来指导我选择应用程序的设置。如果我添加自定义配置部分,如何为我的自定义设置启用智能感知?我相信这个问题一定有一个简单的答案,但粗略的谷歌搜索并没有给我任何帮助。
谢谢!
正如其他答案所说,您需要为自定义配置部分提供 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>
该xmlns
属性仅用于设置默认命名空间,因此您无需在customSection
元素及其所有子元素上设置它。(但是,不要将xmlns
属性放在<configuration>
元素上!)
customSection.xsd
包含 IntelliSense 将使用的架构,例如:
<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>
如果您不想修改 Visual Studio 文件或将任何内容复制到 Visual Studio 文件夹中,可以将.xsd
文件添加到项目中,打开文件并在“属性.config
”窗口中选择“架构” (单击图标):[…]
您需要为您的自定义设置创建一个 XSD 文件并将其复制到您的 Visual Studio 安装的架构目录中。对于 2005,这是:%ProgramFiles%\Microsoft Visual Studio 8\XML\Schemas
这里有一些关于此的信息。 http://blogs.msdn.com/astebner/archive/2005/12/07/501466.aspx