Wednesday, June 10, 2009

Post build script for sharepoint based projects

Scenario:
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

Steps:
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

Code:


@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 )
IISRESET

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
rmdir %TEMPLATEDIR%\FEATURES\MyFeature /S /Q

Echo ==== Done Clean up ===
Echo
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
IISRESET

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

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

0 comments: