Versioning custom workflows in SharePoint 2007

Whilst developing a custom workflow in SharePoint 2007, one of the main problems I encountered was managing changes and updates in the workflow code.  If major changes to the workflow code are performed, when the new solution is released, the original code stops working, causing existing running workflows to stop and error.  The way to get around this is to release a new version of the code as a new solution.   This way the existing workflows continue to run as they are referencing the version one code in the gac, but a new workflow can be added which is running under newly installed code in the gac.

The steps to do this are as follows:

1.  Edit the projects AssemblyInfo.cs file in Visual Studio, changing the AssemblyFileVersion to a new version number.

2.  Using Visual Studio tools, generate a new GUID and change the GUID of the solution in the solutions manifest.xml file.

3.  In your workflows.xml file, copy the existing workflow definition and paste it under your existing workflow definition.
–  Edit the newly pasted code giving it a new name, say “Workflow V2”.
–  Give the newly pasted definition a new GUID.
–  Change the newly pasted code to use the new version number in the codebesideassembly value.

4.  Amend any referenced which use the GUID or name of the new workflow version in your workflow or other code.

5.  Change any front side pages or code which reference the assembly to use the new version number.  I.E aspx pages which have your project dll referenced as an assembly.

6.  Change any cab.ddf scripts used to package the code into a wsp file by giving the wsp file generated a new name.  Say, WorkflowV2.wsp.

7.  If you have an install script for retracting, deleting and deploying the solution, change this so that it references the new wsp file.

Now build your project in Visual Studio and generate the WSP file.  This can be moved to the live server and installed as normal.  If all is well, you should now see a new version of your code in the C:\Windows\Assembly directory.

Finally, in SharePoint, go to your list where you workflow should be running.  Edit the list and add a new workflow.  You should see your new workflow listed.  Then go to the remove workflow option and select “no new instances” of the version one workflow to stop any new version one workflows being run on the list.