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
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.
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.