Solution Deployment with SharePoint 2007

Solution Packages
Solution packages are the preferred mechanism for deploying WSS components. The solution package itself is a compressed CAB file with a .wsp extension, and it contains one or more WSS components along with any dependent files that need to be deployed on each front-end Web server.
A simple solution package might contain just the files needed to deploy a single feature. A more complex package could contain the files for multiple features, applications pages, Web Parts, list definitions, event handlers, and a site definition. You decide what goes into a solution package according to what set of components it makes sense to deploy as a single unit.
The WSS runtime provides a built-in installer component that runs on each front-end Web server and is responsible for uncompressing the files inside a solution package and properly installing its components. The WSS installer requires each solution package to carry additional metadata inside a file named manifest.xml. When the installer is called upon to deploy a solution package, it reads the metadata in manifest.xml to determine exactly which components and files from inside the CAB file need to be extracted and deployed.
Manifest.xml contains metadata to instruct the installer which files need to be extracted from the solution packages and copied into various WSS system directories. But beyond that, manifest.xml also carries metadata that tells the installer to perform other important deployment procedures, such as registering features with the WSS runtime, adding assembly DLLs to the Global Assembly Cache (GAC), and updating the web.config file with SafeControl entries required in Web Part deployment.

Deploying the OfficeSpaceFeature Component
In the May column, I presented a business solution composed of a feature named OfficeSpaceFeature that works together with a custom application page named LetterGenerator.aspx. These two components were designed to work together to create a single business solution.
The sample code that accompanies this month’s column contains a Visual Studio® project named OfficeSpaceFeature. This project contains the source code for both the feature and the application page. While the sample code that accompanied the May column had an earlier version of this project, the download has now been updated to include the extra files needed to build and deploy all the required components and files as a solution package. Note that the project contains a \Solution directory and a \Package directory as shown in Figure 1.
Figure 1 Solution Package Components 
When the OfficeSpaceFeature is activated within the context of a SharePoint site, it provisions a document library named Customer Letters. It also provisions a custom template file named LetterTemplate.docx, which serves as the document template behind the Customer Letters document library. This means that LetterTemplate.docx becomes a dependent file that must be deployed along with the feature within the \FEATURES directory on each front-end Web server.
The feature named OfficeSpaceFeature has also been created with an event handler that fires during feature activation. This event handler is defined within a SPFeatureReceiver-derived class and is compiled into an assembly named OfficeSpaceFeature.dll. WSS requires that any assembly DLL containing event handlers be compiled with a strong name and installed into the GAC to work properly.
Now that you have a basic idea of what components and files make up this business solution, let’s examine the feature.xml file for the feature named OfficeSpaceFeature (see Figure 2). As many other XML-based files used in WSS development, the feature.xml file contains XML that conforms to a WSS-specific language known as Collaborative Application Markup Language (CAML).
 
 
<Feature Id=”AAEC2E08-1CCF-4712-AE5E-A33BEA53A325” 
  Title=”A Sample Office Space Feature”
  Description=”Demoware from Ted Pattison’s Office Space column”
  Version=”1.0.0.0”
  Scope=”Web”
  ImageUrl=”OfficeSpace/PithHelmet.gif”
  ReceiverAssembly=”OfficeSpaceFeature, [full four-part assembly name]”
  ReceiverClass=”OfficeSpaceFeature.FeatureReceiver”
  xmlns=”http://schemas.microsoft.com/sharepoint/”>

  <ElementManifests>
    <ElementManifest Location=”elements.xml” />
    <ElementFile Location=”LetterTemplate.docx” />
  </ElementManifests>

</Feature>
 
 
The Feature element contains an ElementManifests element, which includes both an inner ElementManifest element and an ElementFile element. ElementManifest references a file named elements.xml that contains the CAML to define ListInstance elements, which provision a new document library and a new list. There is also a Module element used to copy LetterTemplate.docx into the context of the current site during Feature activation so it can serve as the document template behind the Customer Letters document library.
The ElementManifest element is an essential part of the Feature definition because it references elements.xml. That file, in turn, adds provisioning instructions that are carried out during Feature activation. But what is the purpose of the ElementFile element? It doesn’t really change the behavior of the Feature itself. Instead, its purpose is to add metadata used by the installer when the Feature has been included within a solution package. The ElementFile element informs the installer that LetterTemplate.docx must be copied to the OfficeSpaceFeature directory as part of the deployment process.
Now let’s turn our attention to the CAML defined in the manifest.xml file (see Figure 3). The manifest.xml file contains a top-level Solution element, which contains inner elements that reference components and files.

No comments:

Post a Comment