After finding countless pages that explain how to do it the hard way (and there are many hard ways), I finally realized one of my favorite sites showed me the easiest, best way, by far. Jeremy Thake of SharePointDevWiki created a video showing how its done. Jeremy is the man downunder! Excuse me, the bloke downunder.
In addition, I also needed to package up two list templates into the solution package, not just one as is done in the video. As with most stuff SharePoint, once you know how to do something, its extremely easy to do.
At a high level, here is what we will do:
- Create some lists in your SharePoint site.
- Install SPSource from CodePlex and use it to reverse engineer the lists you created on your SharePoint site back into list templates, storing the necessary files that make up the list templates into a Visual Studio project.
- Use BuildWSP to build your WSP!
Ok, so now for a little bit of detail.
- In your SharePoint site, create two lists. I will call one Contact List Template and the other Sent Emails Template in this example. Add some columns to them.
- Download SPSource from CodePlex. I put spsource.exe in a folder called d:\deploy, but just put it somewhere easy to get to.
- If you haven't already downloaded and installed WSPBuilder, do it. WSPBuilder will be added under the Tools menu in Visual Studio.
- Create the Visual Studio project that will be the destination for the reverse-engineered list templates.
- In Visual Studio, click File -> New -> Project -> WSPBuilder -> WSPBuilder Project
- Name it MyListTemplates and click OK.
- Add a feature for each list template you wish to reverse engineer. (Note: Trying to add both list templates to the same feature has proven to be problematic. If you add them to the same feature, when you deploy the feature and create lists from the list templates, all the lists you create will only use the definition from the first list template that was deployed, even if you create a list based on the second list template. Therefore, create one feature for each list template!)
- In the Solution Explorer, right-click the project, then click Add -> New Item -> WSPBuilder -> Blank Feature
- Name it ContactListTemplate and click Add.
- In the Feature Settings dialog, change the Scope to Site and click OK.
- Do a. through c. again, but this time name the feature SentEmailsTemplate.
- Notice both features have been added under /12/TEMPLATE/FEATURES/ in your Solution Explorer. Each contains an elements.xml and feature.xml.
- Create a .spsource file for each feature. These files tell SPSource what lists to reverse engineer into list templates.
- In Solution Explorer, right-click the ContactListTemplate feature, then click Add -> New Item -> Common -> XML File, name it contactlist.spsource and click Add.
- In Solution Explorer, right-click the SentEmailsTemplate feature, then click Add -> New Item -> Common -> XML File, name it contactlist.spsource and click Add.
- Copy the contents of elements.xml into both of these .spsource files.
- In contactlist.spsource, add the following inside the Elements tag:
<ListTemplate Name="Contact List Template" /> - In sentemails.spsource, add the following inside the Elements tag:
<ListTemplate Name="Sent Emails Template" />
- In Solution Explorer, right-click the ContactListTemplate feature, then click Add -> New Item -> Common -> XML File, name it contactlist.spsource and click Add.
- In your project's folder, create a text file called SPSource.cmd with these contents:@ECHO OFFBe sure to set DEVSITEURL to your SharePoint site where you created the lists back in step 1.
SET SPSOURCE="d:\deploy\SPSource.exe"
SET DEVSITEURL="http://sharepoint2007:1001/marketing"
%SPSOURCE% -designsite %DEVSITEURL%
PAUSE - Double-click SPSource.cmd so it runs. If you get an error message saying something like "Method not found...SPOpenBinaryOptions...), you need to install Windows SharePoint Services 3.0 Service Pack 1 (SP1). This is because SPSource requires methods that are in WSS 3.0 SP1.
- In Solution Explorer, click Show All Files. Under the two features, you'll see a new folder under each with the same name. Right-click the new folders and click Include In Project.
- Build the project.
- Create the wsp solution file by clicking Tools -> WSP Builder -> Build WSP.
- You can now deploy MyListTemplates.wsp with stsadm as you normally deploy wsps! Use addsolution, deploysolution, and activatefeature to deploy however you want to deploy it (ie using GAC or CAS, etc).
It's really rewarding when you read posts like this and seeing the benefits you get from the work we do in the community ;-) thanks for link to SharePointDevWiki.com on blog too!
ReplyDelete