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.
- Deploy Version 1
- Add Assembly name suffix of “_v1″
- Change Assembly version and File version
- Add a suffix to the workflow Elements.xml file Name element (“v1.0.0.0″)
- Rebuild Solution
- Publish the Workflow
- Add the Solution
- Add-SPSolution -LiteralPath C:\Downloads\Blog\C#\SequentialWorkflow\bin\Debug\SequentialWorkflow.wsp
- Deploy the Solution using Central Administration > System Settings > Manage Farm Solutions
- Activate the Feature
- Add the workflow to Shared Documents
- Make a Version 2 Workflow
- Copy the version 1 dll to a v1.0.0.0 folder
- Change Assembly name suffix to _v2
- Change Assembly version and File version
- Change workflow Elements.xml file > Name element suffix changed to v2.0.0.0
- Include version 1 dll in the Package.package
- Source Path: bin\v1.0.0.0\SequentialWorkflow_v1.dll
- Location: v1.0.0.0\SequentialWorkflow_v1.dll
- Make workflow changes as needed (code and activities)
- Rebuild the Solution
- Publish the workflow project, replacing the existing .wsp file
- Update the Solution
- Update-SPSolution -Identity SequentialWorkflow.wsp -LiteralPath C:\<my path>\bin\Debug\SequentialWorkflow.wsp -GACDeployment
- Add the workflow to Shared Documents
- Allow No New Instances of the version 1 workflow
To achieve this follow the below method:
- Set the workflow assembly version to 1.0.0.0
- Display the properties of the workflow project in Visual Studio
- Add a version suffix to the Assembly name
- Ensure the Assembly version and File version are set to 1.0.0.0
- Add a suffix to the workflow Name in the workflow Elements.xml file
- Rebuild the Solution
- Publish the workflow by right clicking the workflow project in Solution Explorer and clicking Publish…
- In this case, I’m publishing to the Debug folder
- Add the Solution to SharePoint: In the SharePoint 2010 Management Shell typeAdd-SPSolution -LiteralPath C:\Downloads\Blog\C#\SequentialWorkflow\bin\Debug\SequentialWorkflow.wsp
- Deploy the Solution:
- Activate the Feature
- Site Settings > Go to top level site settings (if necessary)
- Site Collection Features
- Click the Activate button if necessary for SequentialWorkflow Feature1
- Add the workflow to Shared Documents
- Shared Documents > Library > Workflow Settings
- Click Add a workflow
- Select SequentialWorkflow – Workflow v1.0.0.0
- Give it a unique name: SequentialWorkflow v1
- Click OK
To test the version 1 workflow:
- Add a couple document to Shared Documents
- Run the SequentialWorkflow v1 workflow against that document
- View the Workflow Information to see the pending task
- Edit the task, setting Status to Completed and % Complete to 100
- Save the task
- 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.
- Save the version 1 dll
- Using steps 1 thru 4 in the Deploy Version 1 section above, set the version of the workflow assembly to 2.0.0.0
- Include the version 1 dll in the new solution
- Modify the workflow code as needed for version 2. In this example I change my logging statement to say “Workflow Version 2 completed”
- Rebuild the Solution
- Publish the SequentialWorkflow project replacing the existing .wsp file
- Using the SharePoint 2010 Management Shell update the Solution: Update-SPSolution -Identity SequentialWorkflow.wsp -LiteralPath C:\<my path>\bin\Debug\SequentialWorkflow.wsp -GACDeployment
- Add the workflow to Shared Documents. See step 11 in Deploy Version 1
- Allow No New Instances of the version 1 workflow
To test the version 1 workflow:
- Make sure you have a SequentialWorkflow v1 workflow In Progress
- Run the SequentialWorkflow v2 workflow against a different document
- View the Workflow Information to see the pending task
- Edit the task, setting Status to Completed and % Complete to 100
- Save the task
- Notice the Workflow History shows a Description of Workflow Version 2 completed
- Complete the task for In Progress SequentialWorkflow v1 workflow
- Notice the Workflow History shows a Description Workflow Version 1 completed
Comments
Post a Comment