Update! A series of posts about using this technique with publishing sites is available here: Using Save Site as Template with Publishing Sites – Introduction
Say you’re working on a new solution that requires certain elements like fields, content types, and list instances to provide data to a Web Part or some other custom functionality. In this post I’ll show you how to create features to provision all of those elements in only a few minutes.
Consider the list shown below. It’s based on the Links list and is bound to a content type named Fun Link. Note that this could just as easily be based on the Custom List template.
The site content type, Fun Link, contains a custom site column, Classification, that provides a set of choices.
Getting this into Visual Studio is easy. Open up the Site Settings page and click the Save site as template link.
Give your template a name. It doesn’t matter what name you choose because the template is just an intermediate step that you’ll throw away when you are done. If you choose Include Content, your new feature will recreate the list data.
When the operation completes, follow the links the your site’s Solution Gallery and save the resulting WSP to your local machine.
Next, open Visual Studio and create a new project. Select the Import SharePoint Solution Package template.
Next choose either Farm or Sandbox deployment. In this example, either works fine.
The SharePoint Customization Wizard displays. You don’t want everything in the wsp, just the items you need to recreate the custom list. Press CTRL+A to select all the items and then SPACE to deselect everything. Now you are ready to select only the items you need. In this case you need the Fun Link content type.
The Classification field…
The Fun Links list instance…
And the ListsFun Links_pages module.
Once you have the set of items you need selected, click Finish. Visual Studio will display the warning shown below telling you about all sorts of dependencies. You don’t need any of them because they are all fields from the core fields feature and are always available on every site. Click No and your done!
Here is a screen shot of the new solution in Solution Explorer.
At this point I probably need to include the features in my main solution. Read How to Copy Feature Elements in Visual Studio SharePoint Solutions to see how it’s done.
Author: Doug Ware