How to create a .wsp file manually
A .wsp file is a deployable, reusable package that contains a set of features, site definitions, and assemblies that you can apply to a SharePoint site and can activate/deactivate individually on your own discretion. MOSS provides a way to bundle all of the components called a solution file which is a cabinet or .CAB-based format with a .WSP extension. A .wsp file can be used to deploy a Web Part, features and other package components to a SharePoint site/site collection/web application/farm. In this post we will see how can we create a .wsp file manually.
When you package a webpart in Sharepoint, it creates a .wsp file and we use this .wsp file to deploy on Sharepoint server. With MOSS 2010, Microsoft have eased the process of packaging webparts. You can right click on Project in solution Explorer and click “Package”, the solution gets packaged and a brand new .wsp file gets generated. However, what if we need to build a .wsp file manually or we need to know what is happening behind the scenes when the packaging this done. This post describes it here… We will be creating a new .wsp file from scratch without using Visual Studio and any 3rd party tools.
For creating the .wsp file, what you need is the .dll file of the webpart and all other custom files(JS, CSS, images) required in your web part. So, let’s start creating a .wsp file. Firstly, we will create a directory structure as below:
- The top level folder name can be anything, I named it TestSolution
- The bin folder is the location where the .wsp file will be created
- The SPWebPart folder is where we will be keeping all our required files. For ease, I have mapped this name to my webpart project name in Visual Studio.
Now, we will create 2 folders in our SPWebPart folder, one for the feature and another for the 12/14 HIVES where Sharepoint stores our custom JS, CSS and images. Please note that the name of folders added here should match the feature name from Visual Studio. Also, since we map the Layouts folder from HIVES in Sudio, we have added the Layouts folder. Also, add another folder inside Layouts with the Project name and a folder with WebPart’s name under the Feature folder. Now the file structure will look something like below:
Now,
- Copy the .dll file of the project in \TestSolution\SPWebPart\
- Copy all JS,CSS, images file in \TestSolution\SPWebPart\Layouts\SPWebPart\
- Copy the .webpart from Visual Studio to \TestSolution\SPWebPart\SPWebPart1_Feature\WebPart1\
- Create a new Feature.xml file in your favorite editor. Store the file in \TestSolution\SPWebPart\SPWebPart1_Feature\ The feature.xml file will look as below, please note that you will need to change the webpart name, if you have it different.
After you have created the Feature.xml file, we need to create a Elements.xml file for the webpart. So, create another file “Elements.xml” in your editor and store it in \TestSolution\SPWebPart\SPWebPart1_Feature\WebPart1\ The file will look as below:
Now, you need to create final XML file named manifest.xml that will be entry point. So, create a new manifest.xml file and store it in \TestSolution\SPWebPart\
The file will look like below:
You can add all the file references under “TemplateFiles” section as mentioned above.
So, now we have everything ready to create a .wsp file. The final step before creating a .wsp file is to create a .ddf (Data Definition File) which will be required by the Makecab utility. Create a .ddf file in an editor and name it wsp.ddf The ddf file will look as below:
Finally, open DOS Prompt and execute the following command:
makecab \f wsp.ddf
After you have executed the command, you will see a SPWebPart.wsp file present in \TestSolution\bin folder.
Please let me know your feedbakc via Comments..