Wednesday, June 10, 2009

Post build script for sharepoint based projects

Visual Studio projects doesn't provide any support for the WSP Deployment. And usually a developer need to perform lot of addition steps to make sure deployment is smooth. Here's a script i commonly used

Assuming you have a single server farm
1. Make sure you have the correct WSP Builder location
2. Make sure to have a Solution folder created where this script will drop the WSP


@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
@SET WSPPBUILDER="C:\Code\WSPBuilder\Buildx86\WSPBuilder.exe"
@SET WSPNAME="MySolution.wsp"
@SET MAINSITEURL="http://localhost"
@SET CENTRALADMINURL="http://localhost:80808"

Echo Creating Solution Package
del Solution\*.* /Q

@echo off
Echo Creating Solution Package
%WSPPBUILDER% -outputpath Solution -wspname %WSPNAME%

Echo Recycling AppPool ( To avoid any file locking issues )

Echo ==== Starting Clean up ===

Echo Deactivating Features
%STSADM% -o deactivatefeature -name MyFeature -url % MAINSITEURL%

Echo Uninstalling Features
%STSADM% -o uninstallfeature -name MyFeature -force

Echo Retracting Solution
%STSADM% -o retractsolution -name %WSPNAME% -immediate
%STSADM% -o execadmsvcjobs

Echo Deleting Solution
%STSADM% -o deletesolution -name %WSPNAME%

Echo Deleting all the deployed files including GAC-ed Assemblied

Echo ==== Done Clean up ===
Echo ==== Starting Fresh ===
Echo Adding Solution
%STSADM% -o addsolution -filename Solution\%WSPNAME%

Echo Deploying solution
%STSADM% -o deploysolution -name %WSPNAME% -immediate -allowGacDeployment
%STSADM% -o execadmsvcjobs

Echo Recycling IIS

Echo Activating Feature
%STSADM% -o activatefeature -name MyFeature -url % MAINSITEURL%

Echo ==== Done fresh deployment ===
This script hold good for sandbox and need changes to script for an other type deployment like Development , Staging and Production.