Testing

webTiger Logo Wide

How To Deploy/Retract SharePoint Solution Packages

SharePoint 2013 Logo

The most common way of deploying SharePoint Solution Packages is at the command line. This is typically done using PowerShell and there are a couple of ways of doing it, that will be discussed here.

Using the STSADM Tool

Microsoft provide a command line tool called STSADM.exe that can be used for administering Windows SharePoint Services (WSS) on-premise. We will start by demonstrating how to deploy and retract solution packages using this tool…

stsadm -o addsolution -filename "%PackageName%"

stsadm -o deploysolution -name "%PackageName%" -allowGacDeployment -url "%TargetWebUrl%" [-local] [-immediate]

stsadm -o enumdeployments

stsadm-o canceldeployment -id "solution-GUID"

stsadm -o retractsolution -name "%PackageName%" -url "%TargetWebUrl%" [-local]

stsadm -o deletesolution -name "%PackageName%" [-force]Code language: plaintext (plaintext)

The commands above do the following:

  • stsadm -o addsolution – installs the solution package on the SharePoint server/farm. It is not deployed to any SharePoint (SP) sites at this point.
  • stsadm -o deploysolution – deploys an installed solution package to a specific SP site. This is done using a SharePoint timer service by default so may not happen immediately. The -immediate switch should be used when deploying into production environments as this uses the SPTimer to schedule the deployment in. The -local switch is really only for development use, and deploys the solution directly (not via SPTimer service).
  • stsadm -o enumdeployments – lists the solution packages that are in the process of being deployed.
  • stsadm-o canceldeployment – cancels a queued/pending solution package deployment.
  • stsadm -o retractsolution – retracts a solution package deployment from a specific SP site. This is done using a SharePoint timer service by default so may not happen immediately. The -local switch is really only for development use, and retracts the solution directly (not via the SPTimer service).
  • stsadm -o deletesolution – uninstalls a solution package from the SharePoint server. The -force switch should be used as a means of last resort only, as it force-deletes the package instead of cleanly removing it (i.e. for use when it cannot be removed any other way!)

You could also try stopping the SPAdmin service and then run stsadm -o execadmsvcjobs to force the administation service jobs to be run immediately.

Using PowerShell

The more modern way of managing packages is by using the PowerShell SharePoint Management library. This offers a similar set of commands to achieve the same outcomes.

To install a solution package:

# Installs the solution to the SharePoint server/farm
Add-SPSolution -LiteralPath "\package-name.wsp" 

# Deploys the solution to all web applications on the server/farm.
Install-SPSolution "package-name.wsp" -GACDeployment -AllWebApplications 

# Deploys the solution to a specific web application.
Install-SPSolution ".wsp" -GACDeployment -WebApplication "web-app-name-here" Code language: PowerShell (powershell)

Notes:

  • The -GACDeployment switch only required if your solution includes .NET Assemblies that need registering in the GAC.
  • -Force switch can be used with Install-SPSolution to force-install it where doing so via SPTimer service isn’t working for some reason.

Once installed, the solution package can be retracted and uninstalled as follows:

# Retracts the solution from all web applications on the server/farm.
Uninstall-SPSolution "package-name.wsp" -AllWebApplications 

# Uninstalls/deletes the solution from the server/farm.
Remove-SPSolution "package-name.wsp" [-Force] Code language: PowerShell (powershell)

Notes:

  • -Force switch can be used to do a ‘dirty’ delete, as a means of last resort only, for use only when clean removal is failing.