Intellisense in onet.xml

Intellisense in onet.xml

This post is the first of several in which I will address issues that are asked during projects on which I work. Of course, to protect confidential information, any names or business related information are changed.
I am a big fan of knowing the nitti gritty details of how a system works. This enables me to piece together an efficient and effective solution that does not contain functionality I or the customer do not need or want.
In SharePoint development, this means wirting, or at least knowing how to write, a site defintion, and the first step is to work with onet.xml. I do prefer to write my own onet.xml since it gives me greater control, however this can be a tedious task unless you have good tools.
To ease the creation of onet.xml in Visual Studio you should use intellisense. By default, Visual Studio does not intellisense onet.xml, but you can make it do so either on a file-by-file basis or for every file, onet.xml or otherwise, that uses a given namespace.
To get intellisense for a single file, open the file i Visual Studio and go to the properties tab, often located on the bottom right:

In the Schema-field, clikc the three dots to browse for a schema file. Find the wss.xsd-file, usually located in ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML’ and click add. That’s it, Visual Studio should now give you intellisense. Test this by placing the cursor at the very beginning of the file and press CTRL+Space. You should see a drop-down such as this:

Now, to tell Visual Studio to use the correct xsd-file (wss.xsd) every time you create an onet.xml-file you need to link an xml-namespace to the wss.xsd file. To do this you need to create one more xml file and also remember to use the correct namespace for your onet.xml files.

First, create a new XML-file in C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas. Call it whatever you like, for instance SharePointCatalog.xml. Open the file and paste in the following:

href="C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd"
targetNamespace="" />

What this actually does is link the ‘targetNamespace‘ with the schema located in ‘href‘. You can use the same technique to link your own schema to any namespace if you use those.

Now, to get Visula Studio to use the intellisense with the schema, add the namespace attribute to the root elemet of your XML file, for instance:


If you now hit CTRL+Space you should get intellisense.

Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It

Published by

Bjørn Furuknap

I previously did SharePoint. These days, I try new things to see where I can find the passion. If you have great ideas, cool projects, or is in general an awesome person, get in touch and we might find out together.

Leave a Reply

Your email address will not be published.