Aug 3, 2013

Merging .NET assemblies into one executable with ILMerge (and why do it)

At my start-up we’ve built our own installer for the Windows desktop part of our application. The goal was an ability to push silent updates with no user disruptions (i.e. similar to Google Chrome). In fact, we treat out desktop app as web app - it’s always of the latest version, and the process of updating it is an irrelevant detail from the user’s perspective. After all, our users don’t care how we update our web app – do we use file copy, pull from Git, or some other process? Nobody cares as longs as it works.

To achieve this goal we used an excellent open source project DDay Update as a starting point. It works in a simple fashion. The user downloads a single EXE file – a bootstrapper. The bootstrapper then connects to our server and downloads the rest of the app and launches it. For auto-updates, the bootstrapper regularly checks our web site for new versions. If there’s one, it repeats the steps above. The installation and auto-updates are essentially the same process.

Which brings me to the subject of this post. The bootstrapper project consists of a primary app (EXE) and several assemblies (DLLs). But, in this configuration it wouldn’t work for us since we want the user to download a single executable file to run. ILMerge solves this problem.

ILMerge is a free command line tool from Microsoft Research. Its syntax is simple:

   1: ilmerge /target:winexe /out:SelfContainedProgram.exe Program.exe ClassLibrary1.dll ClassLibrary2.dll

ILMerge doesn't ship with Visual Studio or any Microsoft SDKs, so you need to manually download it from the Microsoft Research web site. For additional details and examples I recommend this article on Code Project.