gpt4 book ai didi

.net - 为 .config 文件中的自定义部分启用 Intellisense

转载 作者:行者123 更新时间:2023-12-03 07:31:46 25 4
gpt4 key购买 nike

在 Visual Studio 中编辑 .NET 配置文件(app.config、web.config 等)时,我会使用 Visual Studio 的智能感知来指导我选择应用程序的设置。如果我添加自定义配置部分,如何为我的自定义设置启用智能感知?我确信这个问题一定有一个简单的答案,但是粗略的 Google 搜索并没有给我任何帮助。

谢谢!

最佳答案

正如其他答案所说,您需要为自定义配置部分提供 XML 架构文档。无需添加.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属性仅用于设置默认 namespace ,因此您无需在 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>

关于.net - 为 .config 文件中的自定义部分启用 Intellisense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/742905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com