Custom web.config Intellisense
(This is a part of my series Visual Studio Tips and Tricks – III )
There are at times when you would like to have intellisense support for you custom providers like the ones Microsoft provides.
In this post, I will be guiding you on the way how to create a basic intellisense for your BlogEngine.NET provider model for web.config.
You can open your BlogEngine.NET sourcecode or any of your websites to try it. But in this tutorial I will be sticking with BlogEngine.NET source code.
- To make stuffs clean I like to put all my Intellisense files (XSD schemas) in a folder called schemas. Please go ahead and create the folder. Add a new image item to your schemas folder. You can name it anything. Out here for simplicity I will name it blogengine.xsd.
- Change the target namespace to something meaning full. I prefer to have it like
http://schemas.[company name]/product/year/month
but its your choice. For now lets stick tohttp://schemas.prabir.me/blogengine/2009/5
. - Lets first have a look at our web.config file, and try to understand the schema.
<BlogEngine>
<blogProvider defaultProvider="XmlBlogProvider">
<providers>
<add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
<add name="DbBlogProvider" type="BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName="BlogEngine"/>
</providers>
</blogProvider>
</BlogEngine>
- I will not be teaching you how to write XSD schemas. There is a good article at W3schools out here where you can learn more. For now just paste the code to your xsd schema file you created earlier. (Just looking at my code you can already learn a lot about xsd schemas – * I would recommend you to download the code files at the end of the article for better formatting and readability).*
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="blogengine"
targetNamespace=
"http://schemas.prabir.me/blogengine/2009/5"
elementFormDefault="qualified"
xmlns="http://tempuri.org/blogengine.xsd"
xmlns:mstns="http://tempuri.org/blogengine.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="BlogEngine">
<xs:complexType>
<xs:sequence>
<xs:element name="blogProvider" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="providers" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="add" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
<xs:attribute name="connectionStringName" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="defaultProvider" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
- Finally to make your schema work, you will have to add the xmlns attribute to your web.config file which looks like below.
<BlogEngine xmlns="http://schemas.prabir.me/blogengine/2009/5">