How to: Import and Package a Declarative Workflow in Visual Studio


When you create a declarative workflow in Microsoft® SharePoint® Designer 2010, you can save the workflow as a template in a SharePoint solution package (.wsp) file. In some circumstances, you may need to import your workflow template into the Microsoft Visual Studio® 2010 development system, and repackage it as a Visual Studio project—for example, if you want to create a solution package that contains both a declarative workflow and custom-coded workflow activities. This how-to topic describes how to import and package a workflow template in Visual Studio 2010. It outlines a method to deploy a declarative workflow developed in SharePoint Designer as a SharePoint Solution and Feature. When the Feature in the project is set to a scope of Site, activating the Feature in the site collection's Features gallery makes it available to every website in the site collection without requiring it to be separately activated on every website on which it is going to be used.


The solution package (.wsp file) created by this How-to document can be installed only on Microsoft SharePoint Server site collections, not SharePoint Foundation site collections. There is a method (see How to: Create and Deploy Declarative Workflows in Sandboxed Solutions) to create a package that can be deployed to both SharePoint Server and SharePoint Foundation site collections. However, the Feature created in that method has to be separately activated on each website on which it is to be used.


This how-to topic assumes that you have already created a declarative workflow in SharePoint Designer 2010 and saved it as a .wsp file.


To import a declarative workflow into Visual Studio

  1. In Visual Studio 2010, create a new project by using the Import SharePoint Solution Package template.



    It is important to use the Import SharePoint Solution Package template instead of the Import Reusable Workflow template.

  2. In the SharePoint Customization Wizard, provide a valid local site URL for debugging, and then click Next.

  3. Browse to the location of your solution package, and then click Next.


  4. On the Select items to import page, click Finish.


  5. When the solution import completes, use the Replace in Files tool to replace all instances of "workflows/" with "_catalogs/wfpub/" throughout the solution.


    _catalogs/wfpub/ is the virtual directory in which declarative workflow files are stored on each site collection.

  6. Open the .xoml.wfconfig.xml file, and then make the following changes:

    1. In the Template element, change the value of the Visibility attribute to RootPublic from either Public or DraftPublic.
    2. In the Template element, change the value of the DocLibURL attribute to _catalogs/wfpub.
  7. In Solution Explorer, expand the PropertyBags node, and then open the Elements.xml file within the PropertyBags node.


  8. Locate the PropertyBags node for the .xoml.config.xml file, and then change the value of the NoCodeVisibility property to RootPublic from either Public or DraftPublic.

  9. Press F5 to build and deploy your solution. You can use SharePoint Designer to verify that the workflow was added to your target site.