Click here to Skip to main content
15,885,216 members
Articles / Visual Studio / Visual Studio 2010

Custom Site Definition

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Jun 2011CPOL2 min read 16.6K   3   1
Explains the way I generate custom site definition based on the site template imported in Visual Studio 2010

Introduction

This post explains the way I generate custom site definition based on the site template imported in Visual Studio 2010.

When we are going to create a new site definition, most SharePoint developers may know that - Make a copy of OOB, and fewer changes on it.

Background

My target is to create a site definition which has a custom master page and a bunch of customized libraries and lists like task Gantt view, contact bio image views and so on. I can easily add a custom master page in ONET.xml without any issues, but manually setting the custom lists is hard in both aspects of development and debugging. So I started to work on the custom site template which is built by “Save as site template” after setting the lists either in list settings or SharePoint designer. Then I downloaded and imported the sandbox solution file into Visual Studio 2010. I found the solution actually gave us a series of features including lists, view pages, modules, property bags and site template. I also found the features under /Template/Features (See picture 1).

Picture 1

My Solutions

When we open the OOB site definition ONET, I can find site features and web features in the Configuration section (See Picture 2). In Visual Studio sandbox solution, there is also an ONET file used by the site template. In the ONET, there are many features which are generated in custom site template.

Picture 2

Picture 3

I just copy the feature lists section from ONET in site template and replace them in site definition ONET. The new site created by the site definition works well.

Details by Steps

  1. Create a site definition – MYCLIENTSITEDEFINITION which is copied from STS.
  2. Create a site using this site definition and customize lists and library of this site.
  3. Save as site template in site settings page, and save this template as myclient.wsp.
  4. In Visual Studio 2010, create a new project by importing the myclient.wsp and deploy it as a farm solution without DLL by updating solution properties.
  5. Copy <SiteFeatures></SiteFeatures> and <WebFeatures></WebFeatures> from site template solution ONET to site definition ONET and save it.

    (Please remove the lists from site definition configuration. Otherwise, the new lists will conflict with the defined lists.) (See picture 4.)

    Picture 4
  6. Create a new site with the upgraded site definition. The new site will keep all the changes expected that we made in the custom site template.

Conclusion

So far, I could not find many solutions to generate a custom site definition with custom lists. I published this solution (I spent a lot of time to figure out this solution.) in order to hear your opinions or experiences. Also, I'd like to hear your solutions on how to generate a custom site definition easily.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCan't Read Screenshots Pin
AspDotNetDev8-Jun-11 12:51
protectorAspDotNetDev8-Jun-11 12:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.