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

Post a Comment