Thursday, March 21, 2013

SharePoint 2010 - Solution Package and Feature Deployment

Overview
In the previous post I had highlighted on how to create and deploy a SharePoint 2010 feature using visual studio 2010. Usually for development environments, this is the usual practice so that the developer can easily deploy solutions and test\debug it.

But, what if you want to deploy the feature to another server? In this case you might need to provide an installer or deployable solution that deploys all the supporting files to the respective places and also installs and activates the feature.

In SharePoint 2010 we can use solution packages for this purpose and deploy it using STSADM.EXE command which resides in 14 Hive at: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\STSADM.EXE

Solution Package
A Solution Package is a cabinet file (.cab compressed file) with an extension of .WSP—which stands for Windows SharePoint Services Solution Package, provided to automate the process of installing features and customizations.
Through a .WSP package, you can deploy a set of one or more features, automatically copying the files and folders to every front-end server from a centralized management console.
A .wsp contains a solution-specific manifest file, called solution manifest, which is yet another XML file that defines a set of information through some attributes and some child elements.

Creating a solution Package
Create a feature using the steps mentioned in the previous post (SharePoint 2010 - Developing a feature using visual studio 2010). Instead of deploying directly to the site we will create a solution package and use STSADM.EXE to deploy it.

Following are the steps for creating a solution package for this feature:

1) Open the project in visual studio 2010 and select Build->Package.

2) Go the Package folder and open Package.package file. You can see the package name and view/add/remove its contents in the designer view.

3) Click on the Manifest tab and you can see the contents of solution package in XML format which mainly consist of the Assembly location and the Manifest location as shown in the figure below.

4) Now go to the Bin->Debug directory of the current project and you will a file with extension as .wsp. This is the solution package that was created in Step 1.


Solution Deployment and Feature activation using STSADM
Move the WSP file to a convenient location in the file system (E\WSP in my case). Run command prompt as administrator and change directory to 14Hive/bin folder as follows:
CD C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\

Following are the steps for deploying the feature:

1) Adding the wsp solution
STSADM.EXE -o addsolution -filename E:\WSP\SharePoint2010FeatureDemo.wsp

2) Deploying the solution
STSADM.EXE -o deploysolution -name SharePoint2010FeatureDemo.wsp -immediate -allowGacDeployment -force

3) Execute Time Job
stsadm -o execadmsvcjobs

4) Installing the feature 
STSADM.EXE -o installfeature -name SharePoint2010FeatureDemo_Feature1 -force

5) Activating the feature
STSADM.EXE -o activatefeature -name SharePoint2010FeatureDemo_Feature1 -url http://sptechbytes:3000/ -force

6) Custom page deployed
Once the feature is activated you can visit the newly deployed page as shown in the figure below.

Feature De-activation and Solution Retractions using STSADM

1) De-activating the feature 
STSADM.EXE -o deactivatefeature -name SharePoint2010FeatureDemo_Feature1 -url http://sptecbytes:3000/ -force

2) Un-installing the feature
STSADM.EXE -o uninstallfeature -name SharePoint2010FeatureDemo_Feature1 -force

3) Retracting the solution
STSADM.EXE -o retractsolution -name SharePoint2010FeatureDemo.wsp -immediate

4)  Execute Time Job
stsadm -o execadmsvcjobs

5) Deleting the solution
STSADM.EXE -o deletesolution -name SharePoint2010FeatureDemo.wsp -override

6) Custom Page Removed
Once the feature is de-activated, you will no longer be able to view the custom page deployed along with the feature.

References
1) Microsoft SharePoint 2010 Developer Reference, by Paolo Pialorsi - Book

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.