Monday, August 17, 2009

VS 2008 SharePoint Workflow Templates on x64

As acknowledged by MS in the readme file, the SharePoint workflow project templates for sequential and state machine workflows do not work on an x64 machine.

The error is blunt and unhelpful: “A 32-bit version of SharePoint Server is not installed. Please install a 32-bit version of SharePoint server.”

The hurdle to developing a SharePoint workflow in no way requires such involved effort.

Instead:

  1. Create a standard WF workflow from the given .Net 3.0 template of your choice
  2. Add a file called feature.xml with the following content:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature xmlns="http://schemas.microsoft.com/sharepoint/"
             Id="My generated unique GUID"
             Title="My Workflow"
             Description="This feature creates my workflow."
             Version="1.0.0.0"
             Scope="Site">
        <ElementManifests>
            <ElementManifest Location="workflow.xml"/>
       </ElementManifests>
    </Feature>

  3. Add a file called workflow.xml with the following content:

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Workflow
            Id="726DC49B-B3DE-455d-8ACB-A8CA86894F87"
            Name="Expense Report Approval Workflow Template"
            Description="This workflow template enables expense report approvals and payment"
            CodeBesideClass="MyWorkflowNamespace.MyWorkflowClass"
            CodeBesideAssembly="MyWorkflow,Version=1.0.0.0, Culture=neutral, PublicKeyToken=MySigningKeyToken">
            <Categories></Categories>
            <MetaData></MetaData>
        </Workflow>
    </Elements>

  4. Create a folder structure in your project for TEMPLATE\FEATURES\MyFeatureFolder
  5. Add a file called install.bat which automates the tasks of gac registration, feature file copying, feature installation, and IIS resetting. Set this file to be called by a post-build action. The file should contain something like:

    @SET TEMPLATEDIR="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE"
    @SET GACUTIL="C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"
    @SET STSADM="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM"

    Echo Installing in GAC
    %GACUTIL% -if bin\debug\MyWorkflow.dll

    Echo Copying files
    xcopy /e /y TEMPLATE\* %TEMPLATEDIR%

    Echo Installing feature
    %STSADM% -o installfeature -filename  MyFeatureFolder\feature.xml -force

    ECHO Restarting IIS Worker process
    "c:\windows\system32\inetsrv\appcmd" recycle APPPOOL "SharePoint Apps"

  6. Add an OnWorkflowActivated activity to your workflow from the SharePoint activities in your toolbox.
  7. Optionally change the base class on your workflow program class to SharePointSequentialWorkflowActivity
  8. Add the following field declarations to your workflow class:

    public Guid workflowId = default(System.Guid);
    public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

  9. Set the WorkflowProperties property on your OnWorkflowActivated activity equal to your new workflowProperties field.

There is another workaround posted.

I won’t hold my breath, but you can also go vote on the bug in hopes that perhaps a patch will be released. I also imagine that packages for VS ‘10 will not have this problem.

Submit this story to DotNetKicks

1 comment:

John B. said...

I know that the state machine problem will not be present in VS 2010 because WF 4.0 won't support state machine workflows at all, according to this podcast. It has a lot of good information about the next version.