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

 

9 thoughts on “Automate ILMerge for Workflows/Plugins to Merge Multiple Assemblies into One in Dynamics 365

    1. Inogic

      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!

  1. evgeny neiterman

    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.

    1. inogic

      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!

      1. Ruan

        Hi, thanks for the article

        I am also only seeing a JSON file in the ILMerge folder that has been created. Looking at the file it shows that there are only 2 DLLs that are meant to be merged.

        Doing this in VS2019, would that matter?

  2. Vaibhav

    Worked like a charm for me.. Thanks for wonderful post.

  3. Ankit

    Hi ,
    This pretty much help me achieve the result. But I want my dll to be placed in Package Deploy instead of I L merge folder.

    This will pretty much help me deploy changes directly from VS. I am using CRMSDK Template for deployment.

    Do you know where i can change dll output path.

    Regards,
    Ankit

Comments are closed.