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文件中有一个与IoC容器类相关的自定义部分。如何在编辑本节的配置文件时获得智能感知,以及如何删除通知我丢失模式的编译器消息。
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.
我在这里发现了这个问题:app.config configSections custom settings不能找到模式信息,但我不明白它是否适用于我的问题,如果适用,该如何使用答案。
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?
我也找到了这个网页如何获得网络智能感知。在Visual Studio . net中配置和App.config,但是它要求在运行应用程序之前删除xmlns属性。这真的是唯一的/最好的方法吗?
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>
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.
基本上,我希望能够在
2 个解决方案
#1
21
XML Intellisense will not automatically work for a custom configuration section.
XML Intellisense不会自动用于自定义配置部分。
Visual Studio may report warnings on compilation complaining that the attributes of the custom configuration section are not defined. These warnings may be ignored.
Visual Studio可能报告关于编译的警告,抱怨自定义配置部分的属性没有定义。这些警告可能被忽略。
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).
如果您想要对自定义配置部分的XML智能感知支持(或者如果您只是想要“没有发现的模式”警告消失),请在您的DotNetConfig中添加以下行。第一个
<xs:include schemaLocation="YOUR_DIRECTORY\namespace.assemblyname.xsd"/>
The DotNetConfig.xsd file can be found in your Visual Studio 8 (or 9) installation directory in the Xml\Schemas subdirectory.
DotNetConfig。可以在Xml\Schemas子目录中的Visual Studio 8(或9)安装目录中找到xsd文件。
#2
4
If you don't want to modify your DotNetConfig.xsd you could add the xsd configuration "inline".
如果您不想修改您的DotNetConfig。您可以“内联”添加xsd配置。
In your case add the following attributes to the custom section
在您的示例中,向自定义部分添加以下属性
<ServiceContainers xmlns="your_xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="your_xmlns location_of_your_schema">
<Registration ....
</ServiceContainers>
This is useful while testing an xsd locally because location_of_your_schema could be a local path and when you are ready to production change location_of_your_schema to the public url of the xsd file.
这在本地测试xsd时非常有用,因为location_of_your_schema可能是一个本地路径,并且当您准备将location_of_your_schema生成到xsd文件的公共url时。
Note that the xsi:schemaLocation attribute must contain pairs of strings separated by spaces where the first string in each pair is a namespace URI and the second string is the location of a schema.
注意,xsi:schemaLocation属性必须包含由空格分隔的字符串对,每个字符串中的第一个字符串是名称空间URI,第二个字符串是模式的位置。
#1
21
XML Intellisense will not automatically work for a custom configuration section.
XML Intellisense不会自动用于自定义配置部分。
Visual Studio may report warnings on compilation complaining that the attributes of the custom configuration section are not defined. These warnings may be ignored.
Visual Studio可能报告关于编译的警告,抱怨自定义配置部分的属性没有定义。这些警告可能被忽略。
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).
如果您想要对自定义配置部分的XML智能感知支持(或者如果您只是想要“没有发现的模式”警告消失),请在您的DotNetConfig中添加以下行。第一个
<xs:include schemaLocation="YOUR_DIRECTORY\namespace.assemblyname.xsd"/>
The DotNetConfig.xsd file can be found in your Visual Studio 8 (or 9) installation directory in the Xml\Schemas subdirectory.
DotNetConfig。可以在Xml\Schemas子目录中的Visual Studio 8(或9)安装目录中找到xsd文件。
#2
4
If you don't want to modify your DotNetConfig.xsd you could add the xsd configuration "inline".
如果您不想修改您的DotNetConfig。您可以“内联”添加xsd配置。
In your case add the following attributes to the custom section
在您的示例中,向自定义部分添加以下属性
<ServiceContainers xmlns="your_xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="your_xmlns location_of_your_schema">
<Registration ....
</ServiceContainers>
This is useful while testing an xsd locally because location_of_your_schema could be a local path and when you are ready to production change location_of_your_schema to the public url of the xsd file.
这在本地测试xsd时非常有用,因为location_of_your_schema可能是一个本地路径,并且当您准备将location_of_your_schema生成到xsd文件的公共url时。
Note that the xsi:schemaLocation attribute must contain pairs of strings separated by spaces where the first string in each pair is a namespace URI and the second string is the location of a schema.
注意,xsi:schemaLocation属性必须包含由空格分隔的字符串对,每个字符串中的第一个字符串是名称空间URI,第二个字符串是模式的位置。