Just so you know, there are a couple of caveats to this approach as mentioned in the PnP documentation:// NOTE: The lines below (in OfficeDev PnP) wipe/clear all items in the composed looks aka design catalog (_catalogs/design, list template 124).
Also, installing and activating the solution with this method will also automatically activate all Site-Collection level features, even if they have been set to AutoActivate = False

What I have found is, by changing the Major and Minor version numbers (which renames the WSP), you can also use the same method to update an existing solution

Here is my PowerShell script which Installs a solution (if it does not already exist) or updates it if the solution already exists, and the Major or Minor version number is different.

The PowerShell script:

The script is straightforward and similar to the other posts. The main difference from the PnP version being I do not run the DesignPackage.Uninstall method before Installing the solution and I also run the DesignPackage.Applymethod after Installing the solution

1) Install a Solution:

After the script is run, I can see my WSP installed in the solution gallery with the Major and Minor versions I specified:

2) Update a Solution:

To update the solution, first we will need an updated WSP. It should have the relevant sections specified in the UpgradeActions Feature XML element.@cann0nf0dder has a great post on configuring a sandbox solution for update here:Upgrading Sandbox Solutions in SharePoint

Once you have the updated WSP, all you need to do is change the Major and Minor version numbers in the script and Install your new WSP.

After the script is run, I can see my WSP is updated to the new version in the solution gallery with the Major and Minor versions I specified:

This way, the same DesignPackage.Install and DesignPackage.Apply methods can be used for updating sandbox solutions in SharePoint Online.

6 comments:

Great post but the function is called installorupdatesolution so I would expect the first time I run it it installs but second time it updates. However on second run I get an error about needing to deactivate the solution first...feels like it is just install for first time?...

Did you change the major or minor versions in the script when you updated the solution?

When you do the second run, you should change the $wspMajorVersion or $wspMinorVersion variables in the script to indicate that you are updating to a new version of the WSP.

Without specifying new values to the $wspMajorVersion or $wspMinorVersion variables, SharePoint thinks that you are trying to activate the same WSP again and hence you get the "you need to deactivate the solution" error.

First off great script, gets me nearly where I need to be. However, I'm experiencing the same behavior as Mark. If the solution in the gallery is in the Activated state, the Uploading portion of the script fails and cannot overwrite the existing solution. Error: "You cannot delete or modify an active solution. Deactivate the solution first."

The script works perfectly if you manually Deactivate the solution first. Have you discovered a way through powershell to accomplish Deactivating the solution?