When working with Workflow projects in Visual Studio, you can add Sequential Workflows, State Machine Workflows, and Activities to a project by right clicking on the project and selecting Add > Sequential Workflow…, Add > State Machine Workflow.., or Add > Activity… menu options.
The problem I run into is that these menu options are only available if you selected one of the Workflow project templates when adding the project to your solution. How can we add workflows to existing projects in our solutions? There are a few hoops to jump through to make this happen, but it can be done.
- Add references to System.Workflow.Runtime, System.Workflow.Activities, and System.Workflow.ComponentModel to your project. Close Visual Studio and open the csproj file in a text editor. Add the following project type Guids to the PropertyGroup element:
* <pre><ProjectTypeGuids>{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids></pre>
- Add the following Import to the Project element:
* <pre><Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" /></pre>
- Re-open your solution in Visual Studio. The workflow menu options should now be available for your project.