How do I include a web.config custom section schem

2019-03-20 00:49发布

问题:

I've added a new custom section to the web.config of an application.

I have also created a corresponding schema file for the new section definition.

How do I include the schema reference in the web.config so that any developer editing the section has intellisense enabled when dealing with my new custom config section?

I've seen solutions whereby I include the schema reference within the web.config by having to update the [IDE installation directory]\Packages\schemas\xml location? This works but I want to ensure that any new developer checking out the code on a fresh development machine automatically has the intellisense enabled without having to also update their development machine.

回答1:

Add your .xsd file as a solution item (or project item). Visual Studio will automatically use any schema file it finds in a solution. You may have to restart Visual Studio for it to start working.

You will also need to reference the schema in the section element:

<mySection xmlns:name-of-schema>
...
</mySection>