I thought it would be instructive to describe how I build and deploy a SharePoint solution that I have built in Visual Studio 2008. I put this process together before I was aware of WSPBuilder, and probably before WSPBuilder was as popular and mature as it is now. That means that I created my solution manifest and my diamond directive file manually. It also means that although I use the structure of the 12 hive in my solution, I don't do it in quite the same way that you would with WSPBuilder. I also find that the out of the box VS2008 / VSeWSS 1.2 support for workflow development doesn't do solutions in the way I want. I set up my Visual Studio project to do the following on every build ( side note: additional build modes that have different behaviors are sometimes desired - perhaps I'll set that up for my next project). As background, note that I am working in a virtual machine that has MOSS and Visual Studio installed locally.
The Post-Build script in Visual Studio 2008 for my project:
time /T
cd ..\..\deployment
call RollbackDeployment.bat http://%COMPUTERNAME%/pathToSiteCollection <solutionName>
echo end of rollback
time /T
copy $(TargetPath) $(ProjectDir)WebSolutionPackage
echo start install
call Install.bat http://%COMPUTERNAME%/pathToSiteCollection <solutionName>
time /T
What does RollbackDeployment.bat do? It un-installs the previous build:
if "%1"=="" GOTO Problem
echo Retracting previous version of Solution
echo CWD is %CD%
rem URL to site collection is %1 and solution name is %2
call RetractSolutionPackage.cmd %1 %2
echo Deleting previous version of solution
call DeleteSolutionPackage.cmd %2
goto TheEnd
:Problem
@ECHO OFF
echo You must specify the url of the site collection.
:TheEnd
RetractSolutionPackage.cmd does this:
rem STSADM is in the path and so is PowerShell
rem If you are building a workflow, you may want to delete the workflow association before you deactivate its feature.
rem I use a bit of PowerShell that you can find at codeplex.com/psbb to do that.
powershell.exe -NoLogo -Command ".\DeleteAssocation.ps1"
stsadm -o deactivatefeature -name %2 -url %1 -force
rem Note that here I assume my feature name is almost the saem as the WSP filename.
stsadm -o retractsolution -name %2.wsp -immediate
stsadm -o execadmsvcjobs
DeleteSolutionPackage.cmd not surprisingly does this:
stsadm -o deletesolution -name %1.wsp
Now we are ready to install our new build. Install.bat does this:
if "%1"=="" GOTO Problem
if "%2"=="" GOTO Problem
echo Building package
call CreateSolutionPackage.cmd %2
IF %ERRORLEVEL% NEQ 0 EXIT 1
copy "..\WebSolutionPackage\%2.wsp" "."
echo Installing Solution
call InstallSolutionPackage.cmd %2
echo Deploying Solution
call DeploySolutionPackage.cmd %1 %2 %3
rem If we need to restart the OWSTimer service (e.g. for workflows that have delay activities), we use the next two lines.
net stop sptimerv3
net start sptimerv3
echo Done!
rem pause
goto TheEnd
:Problem
@ECHO OFF
echo You must specify the url of the site collection and the package name.
:TheEnd
CreateSolutionPackages does this:
cd ..\WebSolutionPackage
if EXIST %1.wsp del %1.wsp
echo Building DDF file
echo CWD is %CD%
"C:\Program Files\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\makecab" /f package.ddf
IF %ERRORLEVEL% NEQ 0 EXIT 1
del setup.inf
del setup.rpt
rem Next step is so I can easily open the wsp in Windows Explorer to see what's inside.
copy %1.wsp %1.cab
rem to open a Windows Explorer window where you can see the .wsp and the .cab, uncomment the next line.
rem start .
cd ..\Deployment
InstallSolutionPackage does this:
stsadm -o addsolution -filename %1.wsp
IF %ERRORLEVEL% NEQ 0 EXIT 1
DeploySolutionPackage does this:
stsadm -o deploysolution -name %2.wsp -immediate -allowgacdeployment
IF ERRORLEVEL 0 stsadm -o execadmsvcjobs
IF ERRORLEVEL 0 stsadm -o activatefeature -name %2 -url %1
rem Next line is only used for a workflow project. It creates the workflow association
IF ERRORLEVEL 0 C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -NoLogo -Command ".\MakeAssociation.ps1"
So now you can see how I get my project to deploy on build.
Hope you find this helpful.
--Michael