Automate ILMerge for Workflows/Plugins to Merge Multiple Assemblies into One in Dynamics 365

By | June 29, 2018

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.

Merge Multiple Assemblies into One in Dynamics 365

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

Merge Multiple Assemblies into One in Dynamics 365

Step 2: Use command “Install-Package ILMerge.MSBuild.Task” and paste in package manager console.

Merge Multiple Assemblies into One in Dynamics 365

Step 3: Also need to install the ILMerge Package using command “Install-Package ilmerge” in the package manager console

Merge Multiple Assemblies into One in Dynamics 365

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)

Merge Multiple Assemblies into One in Dynamics 365

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.

Merge Multiple Assemblies into One in Dynamics 365

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.

Merge Multiple Assemblies into One in Dynamics 365

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.

Map Dynamics CRM

 

Leave a Reply

Your email address will not be published. Required fields are marked *