How to: Create a Site Definition using Visual Studio 11
Posted
Tuesday, May 29, 2012 11:44 PM
by
CoreyRoth
I’ve posted a number of articles about Visual Studio 11 to date and today’s article talks about the new SharePoint Project Item, Site Definition. This is a new SPI available in Visual Studio 11. Previously, you had to create site definitions manually or using the Community Kit for SharePoint. This new template has enough to get you started. Start off by creating a new blank SharePoint project and then add a new item.
Notice how the Add New Item dialog indicates that Site Definitions are available in Farm Solutions only. Once you create the new item, you’ll have three items created for you visible in the Solution Explorer, a default.aspx, onet.xml, and a webtemp_<sitedefinition>.xml.
I won’t go into the details of the specific of what goes into each specific file, since there are many posts out there already covering that. However, I will show you what each file looks like. We’ll start with onet.xml.
Onet.xml controls the features that the site definition automatically activates as well as custom list instances. The files support IntelliSense so that will help you customize the XML as you can see in this example below.
The WebTemp XML file automatically has the name of the site definition appended to it. You can customize this file with multiple configurations as well as change the category. In the example below, notice that the DisplayCategory is set to SharePoint Customization. If you are deploying multiple site definitions be sure and change the ID to avoid conflicts.
The default.aspx file contains a simple placeholder that gets you started. Of course, you will likely want to create custom WebPartZones to allow someone to add web parts to your page.
Once you have made any customizations that you would like, deploy your solution. One thing to remember when deploying site definitions is that an iisreset is required. When I deployed my solution the first time, it did not show up in the New Site list. I deployed the solution again and I could pick it from the list.
Notice that it’s in the SharePoint Custom category. Create your new site and when it is complete, you should have a site definition that looks like the one below.
That’s what you get. It’s nothing fancy but it might save you a few steps the next time you have to deploy a site definition.