Friday, September 19, 2008

SharePoint: Deploying WebPart/Feature as SharePoint Solution Package (.wsp file) - Part 1

Link to Part 1 : Creating Skeleton (current post)
Link to Part 2 : Creating Features/Webparts
Link to Part 3 : Creating .ddf and Manifest.xml
Link to Part 4 : Using STSADM and Centeral Admin to add and deploy solution

Today, I want to discuss about, how to provision WebPart/Feature as SharePoint deployable solution (i.e. "WSP" file). 
Before we start please make sure you have following pre-requisites:
  1. Visual Studio 2005/2008
  2. Microsoft Cabinet SDK (Download from here)
  3. Microsoft.SharePoint.dll
In this article I'll walkthrough creating:
  1. WebPart (name: handsOnWebpart)
  2. Add new item in SiteActions
  3. Add an "me.aspx" page in Pages Library
  4. Add webpart (handsOnWebpart) on "me.aspx" page
All the above functionality is achieved by wrapping under Feature (name: HandsOnFeature), which is packaged as ".wsp" file.

Following is step by step instructions as how to create a deployable .wsp file:

1. Create a Visual Studio 2005/2008 C# empty project

2. Unzip Microsoft Cabinet SDK (for simplicity sake we will unzip under root project folder)

3. Create following solution structure


Features folder will contain all features

WebParts folder will contain all webparts

DDF file will contain all instuctions for MAKECAB.EXE to create wsp and cab file.

Manifest file will contain all binding information required by SharePoint during installation

4. Make entry in post build event to run MAKECAB.EXE via command line to generate .wsp and .cab file.

Note: Only .wsp file is required for SharePoint deployable solution. We are creating .cab file for our ease so as we can open it and view the file hierarchy.

"$(ProjectDir)makecab.exe" /f "$(ProjectDir)tt.ddf" /D CabinetNameTemplate=test.wsp /D DiskDirectory1=wsp

"$(ProjectDir)makecab.exe" /f "$(ProjectDir)tt.ddf" /D /D DiskDirectory1=cab

Once solution is successfully build, we will see two new folders in bin/debug directory:
  • wsp : contains .wsp file
  • cab : contains .cab file
What have done till now is created a skeleton for our solution.

In my next post I will discuss on how to create ddf file, manifest file, feature, webpart.

No comments: