Sunday, June 17, 2012

Upgrade solution in SharePoint 2010

In this article we will discuss how to upgrade solution in SharePoint 2010 using PowerShell or STSADM. Also you can check my last article on Powershell command to install activate feature SharePoint 2010.

Suppose you have deployed one solution and after that you have modified the code then it is better to upgrade the solution rather than remove the solution and deploy the solution again.

Here is the STSADM command to upgrade solution:
STSADM.EXE -o upgradesolution -name MyCustomSolution.wsp –allowGacDeployment

And the PowerShell command to upgrade solution:

Update-SPSolution -Identity MyCustomSolution.wsp -LiteralPath c:\MyCustomSolutionV1.wsp -GACDeployment

In the background SharePoint updates the .wsp package stored in the configuration database and will synchronize every server in the farm. And also if the new solution contains new dlls, aspx files or any other files then it will copy to the new servers in the farm.
Also the new solution removes some items then it will remove the items from the server.

SharePoint 2010 Object Model code to upgrade solution:

using(SPSite site = new SPSite("http://Site URL"))
{

SPFeatureQueryResultCollection featuresToUpgrade = site.QueryFeatures(SPFeatureScope.Site, true);

foreach (SPFeature feature in featuresToUpgrade)
{
feature.Upgrade(true);
}

}

Also you can check some SharePoint 2010 powershell commands.