Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

Sharepoint Solution Install with WSP Builder Made Easy

4.67/5 (4 votes)
19 Oct 2010CPOL3 min read 32.7K  
This article describes how to set up and build a basic wsp solution file including handy installation scripts

Introduction

This article will describe how to install a basic Sharepoint wsp solution using WSPBuilder and a couple of install scripts.

Background

Installing Sharepoint features can have several challenges, but with a few well placed steps, you can be off and running.

Disclaimer - Hope this helps, if it doesn't, don't bother to harass me about it, you get what you pay for and you got this for free. If this worked for you, vote me a 5!

Getting Started

The first step to installing a feature or other code on your site is to decide which site you wish to install to. Generally Sharepoint allows you to create as many sites on different ports as you like. Once you know which site you want to deploy a solution to, you can then build your solution using WSPBuilder. Below is a typical project hierarchy for a feature with some custom pages in Visual Studio:

Sharepoint-article-image1.JPG

Notice the main content files in a feature deploy are located under the TEMPLATE directory. This allows WSPBuilder to build a .wsp solution file that understands once deployed where to put everything. While building your feature project is fodder for another article in the interest of direction, you can see by the image that there are several sections for content. These are only important in that they reside in their proper place under the TEMPLATE directory. There are several ways to build a WSPBuilder-centric project, this is only one of many.

To build your project, once you have completed development, you must have installed the Visual Studio plugin for WSPBuilder (located here). To create your solution file, you will need to right click on your project, select WSPBuilder and the menu item "Build WSP". This builds a Sharepoint solution file in the root directory of your project.

WSPBuilder-deploy.JPG

Once you have built your solution file, you will need to run some sort of installation script to install it to Sharepoint. Below is a handy one I created. To use it, you only need to change the variables thus:

  • WSPNAME - This is the name of your solution file compiled using WSPBuilder.
  • SERVERSITEURL - This is a combination of your Sharepoint server name, port, and site collection name (if applicable) where you would like the solution deployed.
  • FEATUREGUID - This comes from your feature.xml file, it is the feature id.
@echo off
CLS
SETLOCAL
SET StartDateTime=%DATE% at %TIME%
@SET STSADM="c:\program files\common files\microsoft shared\
		web server extensions\12\bin\stsadm"
@SET WSPNAME="[Your Solution File Name].wsp"
@SET SERVERSITEURL=[your server name: your port name]/sites/[Your Site Collection Name]
@SET FEATUREGUID="[your guid]"
ECHO --------------------------------------------
ECHO ^| %WSPNAME% deployment process ^|
ECHO ^| Started on %StartDateTime% ^|
ECHO --------------------------------------------

TITLE Deploying %WSPNAME% solution...

Echo Add the solution to Solution gallery....
%STSADM% -o addsolution -filename %WSPNAME%
IF %ERRORLEVEL% NEQ 0 GOTO ERR

Echo Deploying the solution across farm.... 
%STSADM% -o deploysolution -name %WSPNAME% -immediate 
	-allowGacDeployment -url http://%SERVERSITEURL%/
IF %ERRORLEVEL% NEQ 0 GOTO ERR

NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback

:iisreset /noforce

Echo Activating feature....
%STSADM% -o activatefeature -id %FEATUREGUID% -url http://%SERVERSITEURL%/ -force

GOTO END

:ERR
TITLE Error!
Echo Error! Deployment has not been completed.

:END
ECHO -
ECHO - Done!
TITLE Done!
SET EndDateTime=%DATE% at %TIME%
ECHO --------------------------------------------
ECHO ^| %WSPNAME% deployment process ^|
ECHO ^| Started on %StartDateTime% ^|
ECHO ^| Ended on %EndDateTime%   ^|
ECHO --------------------------------------------

popd
ENDLOCAL
pause

The FEATUREGUID variable is taken from the feature.xml id attribute:

<Feature 
Id="8682CCBC-C49B-4957-ADAA-708E40C06121" 
Title="SampleFeature" 
Description="This is your feature description, 
notice the scope is 'Site' since this example deploys on the site collection" 
Scope="Site" 
Hidden="false" 
ImageUrl="SampleFeature\icon_contactlist.gif" 
ReceiverAssembly="SampleFeatureProject, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=e30e9c1baed5c190" 
ReceiverClass="SampleFeatureProject.FeatureReceiver" 
xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <ElementManifests> 
        <ElementManifest Location="elements.xml"/> 
    </ElementManifests> 
</Feature>   

Once you have changed the variables in the script, you can run this script and look in the Central Administration/Operations/Solution Management Page to see if errors occurred or if the solution was deployed correctly.

operations-solutiondeploy.JPG

If you ever want to uninstall the solution, here is a script for that as well:

@echo off
CLS
SETLOCAL
SET StartDateTime=%DATE% at %TIME%
@SET STSADM="c:\program files\common files\microsoft shared\
		web server extensions\12\bin\stsadm"
@SET WSPNAME="[Your Solution File Name].wsp"
@SET SERVERSITEURL=[your server name: your port name]/sites/[Your Site Collection Name]
@SET FEATUREGUID="[your guid]"

ECHO --------------------------------------------
ECHO ^| %WSPNAME% uninstalling process ^|
ECHO ^| Started on %StartDateTime% ^|
ECHO --------------------------------------------

TITLE Uninstalling %WSPNAME% solution...
Echo Deactivating feature.... 
%STSADM% -o deactivatefeature -id %FEATUREGUID% -url http://%SERVERSITEURL%/ -force

Echo Retracting the solution from Web farm....
%STSADM% -o retractsolution -name %WSPNAME% -immediate -url http://%SERVERSITEURL%/
IF %ERRORLEVEL% NEQ 0 GOTO ERR

echo Wait for %WSPNAME% to be retracted....

NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback
NETSH Diag Ping Loopback

Echo Deleting the solution from solution gallery....
%STSADM% -o deletesolution -name %WSPNAME% -override
IF %ERRORLEVEL% NEQ 0 GOTO ERR

:iisreset /noforce
GOTO END

:ERR
TITLE Error!
Echo Error! Uninstalling has not been completed.

:END
ECHO -
ECHO - Done!
TITLE Done!
SET EndDateTime=%DATE% at %TIME%
ECHO --------------------------------------------
ECHO ^| %WSPNAME% uninstalling process ^|
ECHO ^| Started on %StartDateTime% ^|
ECHO ^| Ended on %EndDateTime%   ^|
ECHO --------------------------------------------

popd
ENDLOCAL
pause

Points of Interest

Pretty simple, huh? Notice the NETSH Diag Ping Loopback statements, this allows a pause in the scripts to allow Sharepoint to do its thing.... if the uninstall fails or does not complete at any point, just re-run it till it uninstalls the feature completely. Hope this helps, if it doesn't, don't bother to harass me about it, you get what you pay for and you got this for free.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)