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.

VS11SPISiteDefinition

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.

VS11SiteDefinitionSolutionExplorer

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.

VS11SiteDefinitionOnetXml

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.

VS11SiteDefinitionOnetXmlFeature

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.

VS11SPISiteDefinitionWebTemp

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.

VS11SiteDefinitionDefaultAspx

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.

VS11SiteDefinitionDeployed

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.

VS11SiteDefinitionPage

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.

Comments

# Windows 8 Developer Links &#8211; 2012-05-31 | Dan Rigby

Wednesday, May 30, 2012 11:11 PM by Windows 8 Developer Links – 2012-05-31 | Dan Rigby

Pingback from  Windows 8 Developer Links &#8211; 2012-05-31 | Dan Rigby

# SharePoint Daily &raquo; Blog Archive &raquo; You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today

Pingback from  SharePoint Daily  &raquo; Blog Archive   &raquo; You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today

# You Don't Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today

Thursday, May 31, 2012 7:44 AM by SharePoint Daily

Installing Windows 8 means no class action suits against Microsoft . - Dooley Top News Stories The Art

# You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today &#8211; Bamboo Solutions

Pingback from  You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today &#8211; Bamboo Solutions

# You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today &#8211; Bamboo Solutions

Pingback from  You Don&#8217;t Want SharePoint; Office 365 for US Government Released; Windows 8 Preview Ships Today &#8211; Bamboo Solutions

Leave a Comment

(required)
(required)
(optional)
(required)