13.8 Packaging and Deploying Web Parts 375
Chapter 13
13.8 Packaging and Deploying Web Parts
We have shown you how to develop a Web Part and manually deploy it to the
site collection’s Web Part gallery. The manual process can be convenient when
working in a development environment, but when it comes to deploying your
Web Parts in production, you should leverage the Windows SharePoint Ser-
vices 3.0 solution framework. We introduced the solution framework earlier
in the book, but let’s provide a quick recap of its purpose. In essence, the solu-
tion framework provides a method for collating the various components that
comprise a solution, packaging them together into a solution file, and deploy-
ing the solution in a consistent and efficient manner to the SharePoint Farm.
The deployment process can be initiated using stsadm.exe or using the central
administration browser interface via the operations solution management
page. During deployment, the files contained in the solution package are
examined and placed in their appropriate location on the server. If the solu-
tion package contains Web Parts, the Web Parts are placed in their appropriate
location, either the \bin directory or the GAC, and a safe control entry is
added to the Web application’s Web.config file. It should be noted that the
deployment process does not upload, or populate, the Web Part gallery with
the new .Webpart files. To achieve this you need to include the .Webpart file
in your solution package and use a feature to provision the .Webpart file into
the appropriate Web Part gallery. Features are covered in detail in Chapter 16,
Features; however, for completeness we will show you how to provision the
.Webpart file when packaging your Web Parts.
There are three methods available for creating a solution file. The first
involves using the command line tool makecab.exe, the second involves using
a setup and deployment project template in Visual Studio 2005, and the
third method involves using the Visual Studio 2005 Deploy Solution build
menu option. Chapter 11, Introduction to SharePoint Development explains
each method in detail. For the purposes of this chapter, we will focus on the
first technique: building a solution file using makecab.exe.
13.8.1 Packaging the Web Part
When you are creating Web Parts in your development environment, you
will inevitably go through various stages of testing before the final Web Part
is ready for packaging. To test your Web Part, you will need to deploy the
Web Part manually through the steps defined earlier in the chapter. Once
you are happy that the Web Part runs successfully and is production-worthy,
you can package your solution. The following section picks up from the
development and manual deployment of our Web Parts—WebPart1 and
WebPart2.
376 13.8 Packaging and Deploying Web Parts
Step 1: Extracting the .webpart files
Earlier in the chapter we created two Web Parts, WebPart1 and WebPart2,
and deployed them to the Web Part gallery at the root of the site collection.
One of the first things that we will want to do is to export the .Webpart files
associated with WebPart1 and WebPart2 so that we can include them in our
solution file. The following steps show how to extract the .Webpart files from
the Web Part gallery.
1. Using your browser, navigate to the Web Part gallery at the root
of the site collection.
2. Locate the two Web Parts; they should be named WebPart1.Web-
part and WebPart2.Webpart.
3. For each Web Part, click the Edit Properties icon. The Web Part
properties page should appear.
4. From the menu bar, click Export and save the .Webpart files to
your desktop.
13.8.2 Step 2: Package the solution
1. Launch Visual Studio 2005 and open the project that contains
the code for WebPart1 and WebPart2.
2. Within the project, create the folder structure as shown in Figure
13.65.
3. Set the output build path to point to the .dll folder that you cre-
ated in the previous step. We need to do this so that the make-
cab.exe tool can locate the assembly and package it into the .wsp
file.
4. Import WebPart1.Webpart and WebPart2.Webpart into the
TEMPLATE\FEATURES\MyWPFeature\DWP folder in the
project folder hierarchy.
5. Navigate to the TEMPLATE\FEATURES\MyWPFeature folder
and add two new text files. Rename them Feature.xml and Provi-
sionedDWP.xml.
6. Open Feature.xml and insert the code shown in Figure 13.66.
Save the changes.
7. Open ProvisionedDWP.xml and insert the code shown in Figure
13.67. Save the changes.
Get Microsoft SharePoint 2007 Technologies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.