Tag Archives: WSP Deployment

SharePoint 2010–Extracting a .WSP Solution File Out of Your Farm

So any SharePoint consultant who has been out there for a while knows that sometimes you walk into a farm and it’s a mess.  Configurations aren’t right, which at least you have a good change of fixing… However, one of the more interesting situations is when you walk in and the farm is running fine, but the company has a bunch of .WSPs that are deployed to the farm and they don’t know what versions they are or what they do.  So how does one go about extracting a WSP from the farm so that we can then either deploy it to a migration farm or crack it open and reverse engineer it via a .CAB extractor?

Turns out that PowerShell makes it pretty easy for us to look like heroes.  Now why this very useful feature isn’t built into the UI I’ll never know, but if you log into the server and run these commands you’re able to quickly extract the .WSP files that have been deployed to the farm.

$farm = Get-SPFarm
$file = $farm.Solutions.Item("solution.wsp").SolutionFile
$file.SaveAs("c:\wsp\solution.wsp")

Obviously, just substitute the name of the solution you want to extract for the “solution.wsp” in the code.  And it really is just that easy.

Using PowerShell To Automate WSP Deployments to SharePoint 2010

A couple handy Powershell functions I use in my deployment scripts:

 

#First load the SharePoint commands
add-PSSnapIn Microsoft.SharePoint.PowerShell
import-module WebAdministration

function WaitForJobToFinish([string]$SolutionFileName)
{ 
    $JobName = "*solution-deployment*$SolutionFileName*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null) 
    {
        Write-Host 'Timer job not found'
    }
    else
    {
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
        
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
        {
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        }
        Write-Host  "Finished waiting for job..."
    }
}

function DeployWebAppWSP($SolutionName, $DropLocation, $WebApplication)
{

        $SolutionPath = $DropLocation + "\" + $SolutionName
        
        Write-Host "Uninstall Old Solution: "$SolutionName
        Uninstall-SPSolution -identity $SolutionName -WebApplication $WebApplication -confirm:$false

        WaitForJobToFinish 

        Write-Host "Remove Old Solution: "$SolutionName
        Remove-SPSolution –identity $SolutionName -confirm:$false
 
        Write-Host "Add New Solution: "$SolutionName
        Add-SPSolution $SolutionPath
 
        Write-Host "Install solution to web application: "$WebApplication
        Install-SPSolution –identity $SolutionName -WebApplication $WebApplication -GACDeployment

        WaitForJobToFinish 

}

SharePoint deploy timer job stuck “Deploying”

A developer on our team was trying to upgrade his solution and asked for my help since the job was showing "Deploying" and he was receiving an error when trying to execute the upgradesolution stsadm command. The error he received was:

Sharepoint Service Error: A deployment or retraction is already under way for the solution “solutionname.wsp”, and only one deployment or retraction at a time is supported

I was able to resolve the issue by running the stsadm -o enumdeployments.

This gave me a listing of all deployments that were pending on the server. There were a few and it turned out a failed deployment from another developer was blocking this new deployment.

The enumdeployments output gives you the GUID ID for each pending job. I captured each ID and then ran the following command to clear the jobs:

stsadm -o canceldeployment -id <ID>

Once complete, verified that no jobs remained by rerunning enumdeployments command. After that, the original solution upgrade could be completed.

Final note is that if this issue arises, it is not a good practice to repeatedly try stsadm -o execadmsvcjobs. Sometimes this command is run to force a timer job to run when a -immediate is done on a deployment. If you don’t want to wait for the timer, use -local and deploy to each SharePoint farm box individually. The execadmsvcjobs can have unintended consequences.