Merging .NET assemblies using GulpJS and ILMerge

It’s possible to merge a few .NET assemblies into one by using the ILMerge utility. This can be helpful if you want to ship your project results in one assembly but internally you still prefer to break the project into smaller parts (projects and libraries).

Another good practice is introducing build systems like the GulpJS, to your projects, especially if these projects have multiple steps in the build flow.

So in this post I’d like to share my experience of using the ILMerge in the GulpJS build system.

ILMerge CLI

Usually you can install the ILMerge and run utility from the command line, like:

"C:\Program Files\Microsoft\ILMerge\ILMerge.exe" /out:"merged.dll" primary.dll secondary1.dll secondary2.dll /target:dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319

As a result you’ll get a merged.dll that contains all data from the primary.dll, secondary1.dll, and secondary2.dll.

GulpJS Step For ILMerge

GulpJS already provides the ability to call the ILMerge CLI (or any other CLI) via the ‘child_process’ nodejs plugin.
But in my opinion, a much more idiomatic approach is to use a separate GulpJS module for performing the same task.
That’s why I’ve created ‘gulp-ilmerge’ plugin to act as a simple wrapper over the ILMerge.exe.

Simply add this plugin to your dev-dependencies:

npm install --save-dev gulp-ilmerge

And here is the new ‘merge’ build step:

var gulp = require("gulp");
var ilmerge = require("gulp-ilmerge");
 
gulp.task("merge", function () {
  return gulp.src(["./bin/Primary.dll",
      "./bin/Secondary1.dll",
      "./bin/Secondary2.dll"])
    .pipe(merge({
        outputFile: "merged.dll"
      }))
});

I hope this article can be useful for merging assemblies.
Feel free to open an issue on github for ‘gulp-ilmerge’ if you’re missing any functionality.

Keep your build script clean:)

This entry was posted in .NET, build, GulpJS, ILMerge, nodejs and tagged , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s