Month: December 2009

Script to automate the installation of wsp and activation of features

This post is regarding the usage of a simple script to automate the wsp installation and featue activation. Whenever we want to deploy components like custom web parts,  custom user control and custom application pages etc. we use sharepoint solution packages for deployment and then we activate the respective features manually. It is a tediou job to install the wsps and  activate the features manually, if we have multiple solution packages to be deployed. To automate this, we can use the the following script to install wsp and activate features. 

@echo off

set solutionName=SampleSolution
set featureSampleFeature1=SampleFeature1

rem ** Replace this value with the URL of your site **
@set url=http://yourserver/sites/rootsite/subsite

@set PATH=C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN;%PATH% 

stsadm -o retractsolution   -name %solutionName%.wsp -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %solutionName%.wsp -override

echo Adding solution %solutionName% to solution store...
echo ----------------------------------------------------

stsadm -o addsolution -filename %solutionName%.wsp
if errorlevel == 0 goto :deploySolution

echo ### Error adding solution %solutionName%
echo .
goto end

echo Deploying solution %solutionName%...
echo ----------------------------------------------------
stsadm -o deploysolution -name %solutionName%.wsp -url %url% -immediate -allowGacDeployment -allowCasPolicies  -force
stsadm -o execadmsvcjobs 

if errorlevel == 0 goto :activateFeature

echo ### Error deploying solution %solutionName%
echo .
goto end


echo Activating features in solution %solutionName%...
echo ----------------------------------------------------

stsadm -o activatefeature -name %featureSampleFeature1% -url %url% -force

if errorlevel == 0 goto :success

echo ### Error activating features
echo .
goto end

echo Successfully deployed solution and activated feature(s)..
echo .
goto end


In the above mentioned script, you can replace the solutionName with the name of your WSP and SampleFeature1 with the name of your feature to be activated. In this example, i'm activating a single feature. 
You can also mention multiple features in the script, so that multiple feature gets activated using this script.

 Subscribe to my post