Deploying referenced assemblies in CRM 2011 plugins and workflows


If you’ve ever developed a more complex plugin or custom workflow for Microsoft CRM that relies on external libraries you know that it can be tricky to get everything working correctly. The problem is that when the dll is registered using the Plugin Registration Tool included with the CRM SDK, only the metadata for the assembly containing the plugin is actually considered by the tool. This can cause issues at runtime even if the plugin appears to have been registered correctly.

Briefly, there are three ways to deal with referenced code:

1 – Install the assemblies in the Global Assembly Cache.

Installing the assemblies into the assembly cache will allow you to take full advantage of the GACs versioning system, preventing conflicting versions of the same assembly if multiple versions are needed. The downside is that installation of the plugin will require a separate step potentially involving gacutil.exe, which may not be desirable for some deployments. If possible though, the GAC method is the preferred installation method.

2 – Install the assemblies in %Program Files%\Microsoft Dynamics CRM\Server\bin\assembly

As a stopgap method that avoids the GAC but still allows you to deploy referenced assemblies to the CRM server, CRM 2011 will look in the assembly folder under its own installation path while probing for needed assemblies. The upside of this method is that it is easy to deploy dlls by simply copying them to the appropriate folder. The downside is that if many plugins use different versions of the same assembly there could be version conflicts that are difficult to track down.

3 – Include all code in one assembly.

The least desirable option in my opinion is to cram all of the code into the same assembly. If you have access to all of the source code involved you could implement a solution like this where all of the source files are linked from external locations into the same Visual Studio project. If you don’t have the source code, there is a tool from Microsoft called ILMerge that can take multiple assemblies and combine them into a single output assembly. This kind of thing should be taken as a last resort only if for some reason it is not feasible to install the assemblies in one of the first two ways I outlined above.

Hopefully this gives you some insight on how assembly references work in CRM 2011 and lets you hit the ground running.


4 Responses to “Deploying referenced assemblies in CRM 2011 plugins and workflows”

  1. Great article.

    Went searching around to try and find out the best way to deploy external references for my CRM 2011 plugin and this was pretty much the only decent site I could find.

    I think I’ll be using the GAC way (although I could see this being annoying to have to register all of the dll’s across many servers, it does seem the best option though).

    Thanks again!

  2. 2 ben

    You can also bring the assembly into the sandbox as a web resource.

  3. I actually found a pretty slick solution and blogged about it step by step here:

    It essentially allows you to have 1 DLL, with the other DLL’s inside of it!

    • 4 Ivan Kovacek

      If i want my plugin to be a part of an Crm solution, and I want to be able to export the solution to other crm at another server, I suppose that I would have to manually add the referenced dll to GAC on the new server? Seems like a bad practice, actually.

      I have one more question.
      Lets say I have few plugin assemblies, all using the same referenced library, and I want to use ILMerge for every plugin assembly. Each of the plugins would actually contain the same library. I suppose i could have some problems when updating assemblies to crm independently, taking into consideration that assembly of “the referenced” library will change too?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: