SharePoint Workflow Versioning with Visual Studio

I needed a methodology for publishing new versions of SharePoint workflows using Visual Studio. I have a Document Library that has a workflow (we’ll call it version 1). The document, 9-30 Staff Meeting.pdf, is running workflow version 1; waiting on a user to complete a task. However, I’ve changed the code and want new documents to run the workflow with the changes (we’ll call this workflow version 2). Here is the key, while the new document, 10-7 Staff Meeting.pdf,  will run workflow version 2, I need the the already in progress, 9-30 Staff Meeting.pdfdocument, to complete using the existing version 1 assembly.

  1. Deploy Version 1
    1. Add Assembly name suffix of “_v1″
    2. Change Assembly version and File version
    3. Add a suffix to the workflow Elements.xml file Name element (“v1.0.0.0″)
    4. Rebuild Solution
    5. Publish the Workflow
    6. Add the Solution
      1. Add-SPSolution -LiteralPath C:\Downloads\Blog\C#\SequentialWorkflow\bin\Debug\SequentialWorkflow.wsp
    7. Deploy the Solution using Central Administration > System Settings > Manage Farm Solutions
    8. Activate the Feature
    9. Add the workflow to Shared Documents
  2. Make a Version 2 Workflow
    1. Copy the version 1 dll to a v1.0.0.0 folder
    2. Change  Assembly name suffix to _v2
    3. Change Assembly version and File version
    4. Change workflow Elements.xml file > Name element suffix changed to v2.0.0.0
    5. Include version 1 dll in the Package.package
      1. Source Path: bin\v1.0.0.0\SequentialWorkflow_v1.dll
      2. Location: v1.0.0.0\SequentialWorkflow_v1.dll
    6. Make workflow changes as needed (code and activities)
    7. Rebuild the Solution
    8. Publish the workflow project, replacing the existing .wsp file
    9. Update the Solution
      1. Update-SPSolution -Identity SequentialWorkflow.wsp -LiteralPath C:\<my path>\bin\Debug\SequentialWorkflow.wsp -GACDeployment
    10. Add the workflow to Shared Documents
    11. Allow No New Instances of the version 1 workflow

To achieve this follow the below method:
  1. Set the workflow assembly version to 1.0.0.0
    1. Display the properties of the workflow project in Visual Studio
    2. Add a version suffix to the Assembly name
    3. Ensure the Assembly version and File version are set to 1.0.0.0
      Assembly 1.0.0.0
    4. Add a suffix to the workflow Name in the workflow Elements.xml fileElementsv1
    5. Rebuild the Solution
    6. Publish the workflow by right clicking the workflow project in Solution Explorer and clicking Publish…
    7. In this case, I’m publishing to the Debug folder
      Publish1
    8. Add the Solution to SharePoint: In the SharePoint 2010 Management Shell typeAdd-SPSolution -LiteralPath C:\Downloads\Blog\C#\SequentialWorkflow\bin\Debug\SequentialWorkflow.wsp
    9. Deploy the Solution: 
      1. Open Central Administration > System Settings > Manage Farm Solutions
      2. Click on sequentialworkflow.wsp
      3. Click Deploy Solution
      4. Click OK, noticing that it will deploy, Now, and it is using the GAC
        Deploy1
    10. Activate the Feature
      1. Site Settings > Go to top level site settings (if necessary)
      2. Site Collection Features
      3. Click the Activate button if necessary for SequentialWorkflow Feature1
    11. Add the workflow to Shared Documents
      1. Shared Documents > Library > Workflow Settings
      2. Click Add a workflow
        1. Select SequentialWorkflow – Workflow v1.0.0.0
        2. Give it a unique name: SequentialWorkflow v1
        3. Click OK

To test the version 1 workflow:
  1. Add a couple document to Shared Documents
  2. Run the SequentialWorkflow v1 workflow against that document
  3. View the Workflow Information to see the pending task
  4. Edit the task, setting Status to Completed and % Complete to 100
  5. Save the task
  6. Notice the Workflow History shows a Description of Workflow Version 1 completed
Run the SequentialWorkflow v1 workflow against a document again, but do not complete the task. We need this running, so we can test version 2 of the workflow further below in this post.

  1. Save the version 1 dll
    1. In the <project>\bin folder create a new folder called v1.0.0.0
    2. Copy the SequentialWorkflow_v1.dll to the folder
      dll1
  2. Using steps 1 thru 4 in the Deploy Version 1 section above, set the version of the workflow assembly to 2.0.0.0
  3. Include the version 1 dll in the new solution
    1. Solution Explorer > Package
    2. Double click Package.package
    3. Click the Advanced tab
    4. Add > Add exiting assembly
    5. Browse to the v1.0.0.0 folder where you saved the SequentialWorkflow_v1.dll file, select it and click Open
    6. Add a v1.0.0.0\ prefix to the Location
      AddAssembly1
    7. Click OK
  4. Modify the workflow code as needed for version 2. In this example I change my logging statement to say “Workflow Version 2 completed”
  5. Rebuild the Solution
  6. Publish the SequentialWorkflow project replacing the existing .wsp file
  7. Using the SharePoint 2010 Management Shell update the Solution: Update-SPSolution -Identity SequentialWorkflow.wsp -LiteralPath C:\<my path>\bin\Debug\SequentialWorkflow.wsp -GACDeployment
  8. Add the workflow to Shared Documents. See step 11 in Deploy Version 1
  9. Allow No New Instances of the version 1 workflow
    1. Document Library Settings > Workflow Settings
    2. Click Remove a workflow
    3. Set SequentialWorkflow v1 to No New Instances
      NoNewInstances
    4. Click OK

To test the version 1 workflow:
  1. Make sure you have a SequentialWorkflow v1 workflow In Progress
  2. Run the SequentialWorkflow v2 workflow against a different document
  3. View the Workflow Information to see the pending task
  4. Edit the task, setting Status to Completed and % Complete to 100
  5. Save the task
  6. Notice the Workflow History shows a Description of Workflow Version 2 completed
  7. Complete the task for In Progress SequentialWorkflow v1 workflow
  8. Notice the Workflow History shows a Description Workflow Version 1 completed

Comments

Popular posts from this blog

Clearing the Configuration Cache for SharePoint

SharePoint 2013 REST API CRUD Operations

Add List Item Attachments to Task Form using Nintex Workflow and Forms