One more way to merge assemblies for D365 CE

Every new way starts with a story, and here is mine. If you ask yourself what’s wrong with old good ILMerge, tool this story is for you.

Once I had to support a heavily customized system with many integrations. Most of them were build using custom workflow activities. As often happens, there was single project for all of them. This project had about 10 assembly dependencies we had to merge with main assembly using ILMerge utility.  It took up to 2 minutes to build and merge that monster, and about 20 minutes to publish it to D365 (on premise deployment). Total size of merged assembly was about 16 MB.

Someone had to stop it and I started looking for alternative. I found one pretty cool solution for embedding dependent assemblies as resource files, but unfortunately it’s not compatible with sandbox. It was OK for on premise, but I wanted to look to the future so I kept going and finally found what I was looking for. Let me introduce you ILRepack:

This tool use the same technique as ILMerge but it is build on newer versions of Mono instruments so it is more fast and efficient. After migration to ILRepack it took only 16 seconds to build and merge, plus total size of the assembly was reduced to 9 MB. Upload time decreased as well, of course.

Most likely you use MSBuild tasks to automate merge process. Here I can recommend you this one: There are several other tasks on NuGet and GitHub, but it looks like that only this one works 🙂

Warning! This task require configuration to be used with D365!

By default it merges all assemblies found in project output folder. In our case that means that tool is going to merge XRM SDK assemblies as well what’s unacceptable! To override this behavior we need to create ILRepack.targets file in project folder and put custom build configuration there. You should have something like this:


Important part here is to use KeyFile parameter as final assembly must be signed. LibraryPath parameter is recommended as it helps to skip some missing dependencies errors during merge. One more thing to consider is that main assembly should be listed first in InputAssemblies list. Also this configure is friendly to Visual Studio Live Unit Testing, but it’s not required.

That’s it. Happy ILRepack’ing and stay tuned!

p.s. Thing are changing fast nowadays, ILMerge is now open sourced and may be already fixed and updated. May be current version is fast enough to be comparable with ILRepack, but a version I have to use before was published in 2005 and it’s performance was not great.



2 thoughts on “One more way to merge assemblies for D365 CE

  1. Pingback: Bulletproof Project Template – Part 5: Plugins and Workflow with Unit Test Support – FixRM

  2. Pingback: How to make VS to rebuild solution before publishing a plugin with spkl or other tool – FixRM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.