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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
SolutionId="60AB14A4-975F-4ddc-9314-A4E95BD68B0D" xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureManifests>
<FeatureManifest Location="MyWebPart9\feature.xml" />
</FeatureManifests>
<Assemblies>
<Assembly Location="MyWebPart9.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="MyWebPart9, Version=1.0.0.0, Culture=neutral, PublicKeyToken=72d040bf09bc4e29" Namespace="MyWebPart9" TypeName="*" Safe="True" />
</SafeControls>
</Assembly>
</Assemblies>

<ApplicationResourceFiles>
<ApplicationResourceFile Location="MyWebPart9.dll" />

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

</Resources>
</Solution>

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="http://schemas.microsoft.com/sharepoint/"
Id="{B8E5AEC5-8DD4-46b2-B066-CDD8651BEBB7}"
Title="My Web Part"
Description="My Web Part getting deployed with a WSP"
Scope="Site"
ImageUrl="muki.jpg"
>

<ElementManifests>
<ElementManifest Location="webpartsmanifest.xml"/>
</ElementManifests>

</Feature>


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

</Elements>

7. Create "MyWebPart9.webpart" in the same folder with the following content
<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="MyWebPart9.MyWebPart9"/>
<importErrorMessage>Cannot import this Web Part. </importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">MyWebPart9 Web Part</property>
<property name="Description" type="string">Sample Web Part that display label.</property>
</properties>
</data>
</webPart>
</webParts>

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
manifest.xml
MyWebPart9.dll
;
; ** MyWebPart9
.Set DestinationDir=MyWebPart9
MyWebPart9\Feature.xml
MyWebPart9\webpartsmanifest.xml
MyWebPart9\MyWebPart9.webpart
;
; ** MyImages
.Set DestinationDir=TEMPLATE\IMAGES\MyWebPart9
MyWebPart9\muki.jpg

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

2 comments:

Anonymous said...

Great Post Muki !

Rajesh said...

thanks for the post this article helped me a lot