Monday, July 03, 2006

Deploying Web Parts with Solution Packages in WSS v3/MOSS 2007

Back in the good ‘ol days of WSS v2 and SPS 2003, we deployed web parts in CAB files called wppacks.  While wppacks can still be used to distrubute web parts in WSS v3 and MOSS 2007, a more compelling method is now to deploy your custom web parts along with features, site definitions and other artifacts in a SharePoint solution package.

The manifest.xml for a SharePoint solution package that includes web parts might look something like this:

<?xml version="1.0" encoding="utf-8" ?>
<Solution SolutionId="1F693B5D-87CB-4509-83E7-8681E7B032A3"
    <FeatureManifest Location="SPSolutionsDemoFeature\Feature.xml"/>

    <SiteDefinitionManifest Location="SPSolutionsDemo">
      <WebTempFile Location="1033\xml\webtempspsolutionsdemo.xml"/>
    <TemplateFile Location="ControlTemplates\SPSolutions\SPSolutions.Demo.MyUserControlTemplate.ascx"/>
    <TemplateFile Location="ControlTemplates\SPSolutions\SPSolutions.Demo.SimpleControlTemplate.ascx"/>
    <TemplateFile Location="Layouts\ClientQueryTest.aspx"/>
    <Assembly DeploymentTarget="WebApplication"
        <SafeControl Assembly="SPSolutions.Demo.WebParts, Version=, Culture=neutral, PublicKeyToken=e9db3057acd9c0f6"
          TypeName="*" Safe="True" />

Note the <SafeControl> element within <Assemblies><Assembly>.  This same <SafeControl> element will be reflected within SharePoint’s web.config upon successful installation of the solution package. 

The deployable CAB file is built using a tried-and-true utility from Microsoft called makecab.exe.  Makecab has been around since most those smart, young kids at Microsoft still had running noses and can be downloaded as part of the Microsoft Cabinet Software Development Kit.  The command to create a CAB file takes a configuration file or “DDF” as a parameter and looks something like this:

makecab.exe /f package.ddf

The contents of the DDF file tell makecab how to contruct the CAB file.  An  example DDF file might look something like this:

;*** Sample Source Code MakeCAB Directive file example
.OPTION EXPLICIT ; Generate errors
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP ;** All files are compressed in cabinet files
.Set UniqueFiles="OFF"
.Set Cabinet=on
.Set DiskDirectory1=Package
.Set DestinationDir=ControlTemplates\SPSolutions
.Set DestinationDir=Layouts
.Set DestinationDir=SPSolutionsDemoFeature
.Set DestinationDir=SPSolutionsDemo
.Set DestinationDir=1033\xml
;*** <the end>

Once the redistributable cab file is created, we can use the stsadm.exe tool (located in c:\program files\common files\microsoft shared\web server extensions\12\bin\) that comes with SharePoint to actually  deploy the solution package.  Deploying a solution package is a two-step process that first involves adding the package to SharePoint’s solution store like this:

stsadm -o addsolution -filename

And then deploying the solution to a particular scope like this:

stsadm -o deploysolution -name -local -url http://beta


Anonymous said...

Can you plase let me know where I can find the complete schema of the file

Anonymous said...

Congratulation for this post. My team has already done as you describe here, but now I'm researching the best way to avoid replace some config files (customized config files) this way each time we deploy the application, we won't rewrite those files by hand. Do you have an idea about this?

Thanks in advance.

Janakiraman C said...


I tried to add xml and image file as
SiteDefinitionManifest Location="STS"
WebTempFile Location="1033\STS\demotemp.XML"

TemplateFile Location="1033\images\email.gif"/

After creating wsp file when I try to add the wsp to SP solution store it populates an error msg "Cannot find this file specified in manifest file: 1033\STS\ demotemp.xml" I am getting same error for oth the files.

Also rectify whether license key can e done using Solution.

Guide me how to achieve this issue (ASAP)...

Anonymous said...

Awesome post, I referenced your solution pack post at the end of mine. Your the man ;)

Rod said...

Here's a nice easy way to do it for beginners:

Anonymous said...

Hi hello,

My requirement is to Deploy webpart to particular site collection of web application. I have created webpart with user controls. Adding user control dll to bin of web application and webpart dll to GAC. Guide me how to deploy webpart in such a way that it should be available to parituclar site collection.

Abdul Hafees said...

Hi, I have developed custom web part in VS 2005 but I want to deploy it wss 2.0. How can do it?

Thanks in advance.


Anonymous said...


Just a quick question as i am new to sharepoint can we add TemplateFiles to webpart (.cab) deployed in sharepoint server 2003 using the way you mentioned in manifest.xml.
If its not possible can you please let me know an altrenative way of icnluding them in the cab.