"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Sunday, 20 February 2011

“CRM cannot find the plugin assembly or one of its dependencies” OR How to use IL Merge? OR How to merge DLLs?

Have you ever faced this issue when you deployed plugins in MS Dynamics CRM?
“CRM cannot find the plugin assembly or one of its dependencies” 

Here is a free tool from Microsoft to resolve the dependency issues of Assemblies. In simple words, ILMerge will create a capsule dll with all the dependency dlls inside in it.

IL Merge could be downloaded from the following link:




ILMerge is a tool to merge .NET assemblies into one dll. For instance, if you have business layer, configuration layer etc then you could merge all the dlls into a single dll using IL Merge. This is very useful when you develop plugins. We may need to include functionalities of other layers to our plugin. So if you use ILMerge you could merge those dlls along with your plugins dll. This avoids dependency issues while using plugins in MS Dynamics CRM.
 
In ILMerge you could specify the dlls to be merged. It’s very simple to use ILMerge.
Please ensure that the following are in place prior to executing these commands.
1) ILMerge.exe exists in the path provided in the command. 2) The output directory exists in the path provided in the command and also the file paths are valid

IL Merge could be implemented in 2 ways
1) Create a batch file and include the ILMerge code and later execute the batch file.
Code snippet for the batch file:
"C:\Projects\MyProject\Library\ILMerge" /t:library /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /copyattrs /keyfile:"C:\Projects\MyProject\Library\mykey.snk"
/out:"C:\Projects\MyProject\Plugins\OutputPluginsLibrary\ PluginsLibrary.dll"  "C:\Projects\MyProject\Plugins\ bin\Debug\Entities.dll" "C:\Projects\MyProject\Plugins\ bin\Debug\Plugins.dll"

2)  Include the ILMerge code in the BUILD EVENTS of the Class Library Project.
Place the following code snippet in the build event as shown in the screen shot
  "$(SolutionDir)Library\ILMerge" /t:library /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /copyattrs /keyfile:"$(SolutionDir)Library\mykey.snk" /out:"$(SolutionDir)Plugins\OutputPluginsLibrary\ PluginsLibrary.dll" "$(SolutionDir)Plugins\$(OutDir)Entities.dll" "$(SolutionDir)Plugins\$(OutDir)Plugins.dll"


This code execution will be done on a successful build.
Macros used:
$(SolutionDir) - The directory of the solution.
$(OutDir) - Path to the output file directory, relative to the project directory.
On a successful scenario, you could see a combined dll in the corresponding output directory. This dll will not cause any dependency issues when it’s deployed in Dynamics CRM Environment.

3 comments:

  1. In my package solution, I have one plugin. Which refers the external dll. When I write the code, the classes of the external dll are available. Its built successfully. But when deploy the package above error comes. How ILMerge can help me?Say my plugin dll is A, and external is B, I merged A & B and made A at other location. How can I use the merged dll A in a solution?

    ReplyDelete
  2. hello there, sorry for the delayed response. So my suggestion is to merge the necessary dlls using IL merge, and you could refer the above post or any other resource.
    Now, as you recommended, imagine you dlls A & B. Also consider , 2 environments DEV and Production. So after using IL merge, you would get a merged dll. So you could register this dll to your DEV organization using plugin registration tool. After registering you could get the option to add the dll & plugin steps to your solution. You refer this post http://crmdm.blogspot.com/2011/03/plugin-deployment-in-crm-2011-best.html . Hence, when you import this solution to Production environment, you will have the plugins & steps inside the solution. Hope this helps.

    ReplyDelete
  3. Can you explain point No 2 Regarding Build Events in Detail .
    Worked it out exactly in the manner you adviced but getting an error 9009

    ReplyDelete