SharePoint smartsolutionupgrade stsadm command

By | September 2, 2009

I just released a new stsadm command in the Trentacular SharePoint 2007 Features CodePlex project called smartsolutionupgrade. The purpose of this command is to perform Solution upgrades in a smart manner by performing the following actions:

  1. Accepts as input either a single Solution filename or a filename of a text file containing a list of Solutions to be upgraded
  2. Extracts and parses the Solution manifest file from each existing Solution to be upgraded in order to determine the Features that will be affected by the upgrade
  3. Inventories the deployment states of the existing Solutions
  4. Inventories the activation states of the affected Features at all scopes within the SharePoint Farm
  5. Deactivates all affected Features
  6. Retracts each of the existing Solutions and deletes them from the Solution store
  7. Adds the updated Solution to the Solution store
  8. Deploys each of the upgraded Solutions according to their previous deployment state
  9. Activates all affected Features according to their previous activation state

Usage

stsadm -o smartsolutionupgrade [-filename <Solution filename>] [-filenamelist <Path to text file containing each of the solution filenames on separate lines>]

Job Definition Execution

Included in the project is a Job Definition Executor that takes care of running one-time scheduled service jobs and waiting for their completion before releasing control. One particular issue addressed by the Job Definition Executor is the “A web configuration modification operation is already running” error caused by successive execution of the stsadm -o activatefeature command on Features that perform web configuration modifications.

In a multi-server farm, web configuration modifications are delegated to Timer Jobs; therefore, the return from execution of the activatefeature command does not mean the Feature activation (and thus the web configuration modification) has completed. So you might say, well duh, you need to also execute the execadmsvcjobs command, but this command simply kicks of the job execution and returns from execution while still not waiting for the jobs to actually complete.

The Job Definition Executor solves this problem by kicking of the jobs and monitoring for their completion. We can now safely execute multiple web configuration modification Features in sequence.

Update

I just released a second stsadm command called smartexecjobdefs that simply wraps the Job Definition Executor and can be used as a substitute for the execadmsvcjobs command.

11 thoughts on “SharePoint smartsolutionupgrade stsadm command

  1. Henrik Binggl

    Hi Trent,

    Just a question concerning the smart solution upgrade. Any experience with a solution upgrade with a huge number of site-collections. In my case I have a solution with some 20+ features used in some 2000 site-collections.

    A solution-upgrade activating/deactivating all of them would take ages?

    Any hints.

    \Henrik

  2. Trent Post author

    Agree that would take a while.

    I’ve thought about adding an additional input parameter that accepts a path to a text file containing a list of feature ids/names to ignore.

    If you know in advance a particular feature doesn’t require “reactivation” upon the solution being redeployed, you could add it to this list.

    Do you think that would do the trick?

  3. Bernd

    Hi Trent,

    Great tool. You must have put a lot of work into it. I just have one suggestion. It would be cool to have a command line switch for feature activation/deactivation. In my case I cannot re-activate features on each deployment for all solution packages.

    Kr., Bernd.

  4. Perry

    Trent,

    What is this block of code doing?
    (current codeplex version of SmartSolutionUpgradeCommand.cs, c. line 156)

    var deploymentManager = new DeploymentManager
    {
    JobDefinitionExecuter = JobDefinitionExecuter
    };

    The DeploymentManager class has no explicit constructor, so its default constructor takes no arguments. What is that code block there — which is anyway not surrounded by parens, so I can’t figure out syntactically what it is? (I expect this is some dynamic programming that is unfamiliar to me — if you could point me in the right direction, say with a keyword, I’d greatly appreciate it.)

  5. Trent Post author

    @Perry,

    The above code block is using a language feature introduced in C# 3.0 called Object Initializers. The equivalent C# 2.0 code would read as follows:

    DeploymentManager deploymentManager = new DeploymentManager();
    deploymentManager.JobDefinitionExecuter = JobDefinitionExecuter;

    Hope that helps.

  6. Trent Post author

    I have a new version I have yet to commit to CodePlex of this stsadm command that accepts two new optional arguments: featurewhitelist and featureblacklist. Each would refer to a text file with a list of Feature IDs to either include or exclude for the Feature deactivation/reactivation steps. Due to current time constraints, getting this committed to CodePlex has been low on my priority list. If this is something you want sooner rather than later, let me know and I can see what I can do to expedite updating CodePlex.

  7. Perry

    I downloaded the latest source and compared it to the 1.9 tag, and it was the same (for the Deployment subdirectory — and I’m interested in the smartsolutionupgrade).

    I compiled these two projects/dlls Trentacular.SharePoint.WSPUtil.dll and Trentacular.SharePoint.StsAdmin.dll, and copied them into the GAC (dropped them into c:\windows\assembly). Then I copied stsadmcommands.trentacular.xml into C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG.

    Then I went to the 12 bin directory and executed “stsadm -help smartsolutionupgrade”, and I get an unhandled exception (‘System.ArgumentNullException’) occurred in STSADM.EXE. ArgumentNullException was unhandled. Value cannot be null. Parameter name: type.

    I wonder if you have any suggestions.

    I was hoping to use VS2008 debugger and walk through a sample invocation of your code, to get familiar with how it works, because the smartupgradesolution sounds like a great idea.

    Background: I’m deploying site columns, so I need my feature receiver to SPField.Update them on activation and SPField.Delete them on deactivation, to update all child/list columns, and to avoid disconnecting/orphaning customized site columns — and all that means that I need to deactivate & reactivate every feature instance upon solution redeployment.

  8. Perry

    (Wow, talk about instantaneous response. At the moment my main goal is to get familiar with your source, b/c it sounds like it does just what I want — and the source code so far looks really good.)

  9. Trent Post author

    @Perry,

    It sounds like you deployed it correctly. The way I am deploying the solution is using the Visual Studio WSPBuilder Extensions. You should be able to open the VS solution, right-click on the Trentacular.SharePoint.StsAdmin project, choose WSPBuilder -> Build Solution, and the once again right-click on the project and choose WSPBuilder -> Deploy Solution which will globally deploy the solution.

    You could try adding a Thread.Sleep(10000) to the top of the BaseStsAdmCommand class’s GetHelpMessage method to give you time to attach to the process in order to debug.

  10. Perry

    Yeah, I use the WSPBuilder solution for production deployments as well. For development I often do it manually — but even then, the right-click WSPBuilder->GAC is very convenient :)

    I’m going to experiment some more with picking it up in the debugger, b/c I really would enjoy walking through it. It uses some LINQ and some stuff that I’ve not gone around to learning, and I’d like to use the exercise of going through this code to incent me to get familiar with that.

  11. Perry

    Turns out that “ArgumentNullException was unhandled. Value cannot be null. Parameter name: type.” is the error obtained when an stsadm extension cannot be loaded. I reregistered by DLLs in the GAC and solved it. Then I deliberately altered the namespaces listed in the xml file, to test that a unresolvable assembly reference in the stsadm xml does lead to that error.

    Now I can happily walk through the source code (I’m just invoking it directly from the VS2008 debugger, using Debug commandline pointing at stsadm commandline).

Leave a Reply

Your email address will not be published. Required fields are marked *