Wednesday, January 6, 2010

SharePoint Solution Deployment

Every time you develop Project Server solutions you are faced with deployment procedure.

Two main steps of getting SharePoint solution installed are adding solution to the solution store and solution deployment. The solution deployment can be performed either with help of GUI or using the STSADM tool, whereas adding the solution to the solution store can be done only by using STSADM. Therefore we recommend using STSADM tool for the entire procedure.

Example of a batch file is shown below:

@echo off
SET STSADM="c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\STSADM.EXE"
SET FEATURENAME="Programs_Programs"

echo Deactivating Programs feature
%STSADM% -o deactivatefeature -name "%FEATURENAME%" -url "%SITEURL%"

echo --- Attempting to deactivate/retract existing solution...
%STSADM% -o retractsolution -name %SOLUTIONNAME% -immediate
%STSADM% -o execadmsvcjobs 
%STSADM% -o deletesolution -name %SOLUTIONNAME% -override 

echo --- done --- 
%STSADM% -o execadmsvcjobs 

echo --- Adding solution to solution store...
%STSADM% -o addsolution -filename %SOLUTIONNAME%
if errorlevel == 0 goto :deploySolution

echo ### Error adding solution
echo . 
goto end

echo --- Deploying solution 
%STSADM% -o deploysolution -name %SOLUTIONNAME% -immediate -allowGacDeployment -force
%STSADM% -o execadmsvcjobs 

if errorlevel == 0 goto :deploySolutionSuccess

echo ### Error deploying solution
echo .
goto end

echo Activating Programs feature
%STSADM% -o activatefeature -name "%FEATURENAME%" -url "%SITEURL%"
if errorlevel == 0 goto :success
goto error

goto :end

echo Solution and feature install successfully


Everything works fine unless “SharePoint 2010 Administration” windows service is started. Started service prevents the “%STSADM% -o execadmsvcjobs” command for successful execution. On the other hand if you remove the “execadmsvcjobs” command, “deploysolution – activatefeature” (and also “retractsolution - deletesolution”) command sequence will not execute synchronously. For these commands a timer job will be created and the second command (“activatefeature” or “deletesolution”) is going to be executed immediately. The solution can’t be deleted until it’s not yet retracted and the feature can’t be activated until the solution isn’t yet deployed. So you will get an error in this case.

To solve this problem we strongly recommend adding the following command to the very beginning of the batch file:

net stop SPAdminV4


net start SPAdminV4

to the very end.

Commands above stop and start “SharePoint 2010 Administration” service.

One more thing related to updating Project Server’s workflow. To apply your changes you have to restart “Microsoft Project Server Events Service 2010” and “Microsoft Project Server Queue Service 2010” windows services after deploying solution (workflow). You can do that using the following commands:

@echo off
echo stop Timer..
net stop SPTimerV4
echo stop Queue..
net stop ProjectQueueService14
echo stop Event..
net stop ProjectEventService14
echo start Event..
net start ProjectEventService14
echo start Queue..
net start ProjectQueueService14
echo start Timer..
net start SPTimerV4
echo All done...
rem pause
@echo on