Introduction:
Recently we got a business requirement where we need to merge two assemblies into single exe i.e. one .net assembly and another assembly which would serialize and deserialize, so we used Newtonsoft.Json.dll for it. To merge Newtonsoft.Json.dll with .net dll in single exe it is recommended to use ILMerge.
ILMerge is a tool that can combine multiple DLLs into a single exe. For this every time, we need to manually merge the assembly using ILMerge UI as shown below.
This blog explains the basics of using ILMerge to create a single Workflow/Plugin DLL without using ILMerge tool externally every time.
Step 1: Add ILMerge.MSBuild.Task using Nuget to your Visual Studio project:
Navigate to Visual Studio Project → Tools → Library Package Manager → Package Manager Console
Step 2: Use command “Install-Package ILMerge.MSBuild.Task” and paste in package manager console.
Step 3: Also need to install the ILMerge Package using command “Install-Package ilmerge” in the package manager console
Step 4: Build your project. After successful build one new folder is created with the name ILMerge. The merged assembly will be stored in an ILMerge folder under the project output. (Need to merge Crm.Workflow.dll and Newtonsoft.Json.dll)
Step 5: Merge Output is present in the ILMerge folder (Under ILMerge Folder Crm.Workflow.dll is merged output).The merged dll contains the component of both the dlls (i.e. Newtonsoft.Json.dll, Crm.Workflow.dll). Now you have to use this dll (i.e. Crm.Workflow.dll) for further processes to reflect the changes in your CRM.
Step 6: By default, all references with Copy Local equals true are merged with your project output. To avoid merging of CRM SDK DLLs and Microsoft.IdentityModel.DLL into our DLL we need to select the three files and set the property “Copy Local” to false.
Conclusion:
Merging of multiple dlls using external tool is time-consuming and somewhat annoying. So simply type the commands Install-Package ILMerge.MSBuild.Task, Install-Package ilmerge in package manager console of your project and after successful installation, rebuild your project and you will get newly merged dll for further processing to reflect changes in your CRM.
Thanks for continuously sharing helpful D365 articles, I recall Microsoft stating “8/31/15This post has been edited to reflect that Dynamics CRM does not support ILMerge. It isn’t blocked, but it isn’t supported, as an option for referencing custom assemblies” – https://blogs.msdn.microsoft.com/crm/2010/11/09/how-to-reference-assemblies-from-plug-ins/
Does this mean Microsoft has since changed their stance on this, or is this still unsupported?
Microsoft mentions in their blog post that the use of ILMerge is unsupported. The method described above is therefore not supported by Microsoft and should be used with caution.
Thanks!
step 4 isn’t working for me. I see the new folder but I only get a JSON file in it. the assembly and the dll are still only in the original location.
Hi,
Could you please check whether all references with Copy Local equals false, keep only two references true which you want to merge and check if issue resolve.
Thanks!