Update 12/3/2011: Microsoft.Activities is now Microsoft.Activities.Extensions
When I first saw NuGet I knew I had to find a way to take advantage of this great new way to deliver code to you. It took a few months but finally the other day I decided to spend an afternoon working on a NuGet package for Microsoft.Activities. Two and a half days later (isn’t that how it always goes) I produced packages for Microsoft.Activities and Microsoft.Activities.UnitTesting
If you don’t already have NuGet, install it now (you will have to restart Visual Studio if it is already running)
Your project can be any kind of project. NuGet will automatically add references that are required. For this example, I’m going to create a Class Library project.
If you would rather have a UI to browse packages,
The Microsoft.Activities package includes a version built for .NET 4 Platform Update 1. As you see in the folder structure there are Net40 and Net401 folders. NuGet automatically detects which version of the .NET Framework your project is targeting and will add a reference to the appropriate version
If you change your target framework after installing your project will continue to reference the .NET 4 version of Microsoft.Activities. You can update the reference manually by browsing the packages folder and adding a reference or you can uninstall / reinstall the package.
Toolbox activities remain in the toolbox across projects. When you create a new project and open the workflow designer you will see the Microsoft.Activities and Dictionary tabs. When you drag one of these activities onto the workflow designer, Visual Studio will add a reference to the assembly that the toolbox icon is associated with.
If you installed the Microsoft.Activities package to a project named ClassLibary1 and then created another project named WorkflowConsoleApplication1 as soon as you start dragging an activity onto a workflow from WorkflowConsoleApplication1 you will see an assembly reference added to the Microsoft.Activities package installed under the ClassLibrary1 solution.
If you try to delete it while Visual Studio is open you will get an error because Visual Studio has the assembly loaded. If you close Visual Studio and delete the solution, the next time you run Visual Studio and open the Workflow Designer you will see the icons are still in the toolbox. However when you try to drop an activity from the missing assembly, Visual Studio won’t allow it because it is unable to locate the assembly to add a reference.
Each time install the Microsoft.Activities package, if the toolbox icons exist, they are removed and replaced with a toolbox icon that refers to the Microsoft.Activities assembly that is installed with the package in current project.
If you change the name of the Tab group from Microsoft.Activities to something else, the package installation script won’t find the activities and won’t update them. However it will add a new activity group.
Sometimes you will get an error when trying to uninstall because Visual Studio has one of the assemblies open. In this case you will have to manually delete the package.
PM> Uninstall-Package Microsoft.Activities
Successfully removed 'Microsoft.Activities 18.104.22.1686' from WorkflowConsoleApplication10.
Access to the path 'd:\ngt\WorkflowConsoleApplication10\packages\Microsoft.Activities.22.214.171.1246\lib\Net40\Microsoft.Activities.dll' is denied.
Access to the path 'd:\ngt\WorkflowConsoleApplication10\packages\Microsoft.Activities.126.96.36.1996\tools\Microsoft.Activities.NuGet.dll' is denied.
The directory is not empty.
Not to worry. Microsoft.Activities.UnitTesting has a dependency on the Microsoft.Activities package so NuGet will automatically deploy it as well.
PM> Install-Package Microsoft.Activities.UnitTesting
'Microsoft.Activities (≥ 1.8.1)' not installed. Attempting to retrieve dependency from source...
Successfully installed 'Microsoft.Activities 188.8.131.529'.
Successfully installed 'Microsoft.Activities.UnitTesting 184.108.40.2069'.
Successfully added 'Microsoft.Activities 220.127.116.119' to WorkflowConsoleApplication14.
Successfully added 'Microsoft.Activities.UnitTesting 18.104.22.1689' to WorkflowConsoleApplication14.
PM> Uninstall-Package Microsoft.Activities
Uninstall-Package : Unable to uninstall 'Microsoft.Activities 22.214.171.1249' because 'Microsoft.Activities.UnitTesting 126.96.36.1999' depends on it.
At line:1 char:18
+ Uninstall-Package <<<< Microsoft.Activities
+ CategoryInfo : NotSpecified: (:) [Uninstall-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UninstallPackageCommand
I’m really happy with NuGet so far. I just updated the uninstall scripts so that they will remove the toolbox tabs (Microsoft.Activities, Dictionary and Unit Testing) created by the install scripts. Of all the things these packages do the interaction with the toolbox is the one area that I’m not sure about. Hopefully what I’ve done here will work for you. If not, tell me how we can do it better.
Ron Jacobs http://blogs.msdn.com/rjacobs Twitter: @ronljacobs http://twitter.com/ronljacobs