Monday, 10 March 2008

Preparing a WSP to deploy a webpart as a feature

Steps in creating a WSP
1. After the webpart is built and compiled.

2. Create a folder "Deployment"

3.Prepare manifest.xml with the following content
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns:xsi="" xmlns:xsd=""
SolutionId="60AB14A4-975F-4ddc-9314-A4E95BD68B0D" xmlns="">
<FeatureManifest Location="MyWebPart9\feature.xml" />
<Assembly Location="MyWebPart9.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControl Assembly="MyWebPart9, Version=, Culture=neutral, PublicKeyToken=72d040bf09bc4e29" Namespace="MyWebPart9" TypeName="*" Safe="True" />

<ApplicationResourceFile Location="MyWebPart9.dll" />

<RootFile Location="TEMPLATE\IMAGES\MyWebPart9\muki.jpg" />
<Resource Location="MyWebPart9\MyWebPart9.webpart" />


4.Create folder "MyWebPart9"in Deployment folder -- this should have same name as webpart file.
(Deployment folder should contain the DLL)

5.Prepare feature.xml in same folder with following content
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns=""
Title="My Web Part"
Description="My Web Part getting deployed with a WSP"

<ElementManifest Location="webpartsmanifest.xml"/>


6. Create "webpartmanifest".xml file with following content in the \Deployment\MyWebPart9 folder
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
<Module Name="MyWebPart9" List="113" Url="_catalogs/wp">
<File Url="MyWebPart9.webpart" Type="GhostableInLibrary">
<Property Name="Group" Value="muki"></Property>


7. Create "MyWebPart9.webpart" in the same folder with the following content
<?xml version="1.0" encoding="utf-8"?>
<webPart xmlns="">
<type name="MyWebPart9.MyWebPart9"/>
<importErrorMessage>Cannot import this Web Part. </importErrorMessage>
<property name="Title" type="string">MyWebPart9 Web Part</property>
<property name="Description" type="string">Sample Web Part that display label.</property>

8.Copy the Image to this same folder, which serves as a Icon to our feature in the activation screen

9.Create "MyWebPartDeploy.ddf"file in the Deployment folder with the following content
.OPTION EXPLICIT ; Generate errors
.Set CabinetNameTemplate=MyWebPart9.wsp
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP;** All files are compressed in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=Package
; ** CAB Root
; ** MyWebPart9
.Set DestinationDir=MyWebPart9
; ** MyImages
.Set DestinationDir=TEMPLATE\IMAGES\MyWebPart9

10. Execute the following command
makecab.exe -f DEPLOYMENT\MyWebPartDeploy.ddf

11. Execute the following command to add the WSP to solution store in portal
stsadm -o addsolution -filename MyWebPart9.wsp

12. Execute the following command to deploy the wsp to portal
stsadm -o deploysolution -name MyWebPart9.wsp -url http://servername:portnumber-immediate -allowGacDeployment


Anonymous said...

Great Post Muki !

Rajesh said...

thanks for the post this article helped me a lot