Merging .NET assemblies into one executable with ILMerge

Splitting code into assemblies in .NET is a useful technique that enables building scalable applications. But, it produces an executable with a number of satellite assembles. All of them need to be deployed to the target system for the app to work. Most of the time installers (MSI-packages) handle this task. But, sometimes it would be very convenient to have one self-contained executable file to share with someone for quick testing by e-mail or Dropbox (or any other service).

I looked at several tools including SmartAssembly from Red Gate and ILMerge from Microsoft. SmartAssembly has a nice GUI and works fine, but pricey at > $795. ILMerge, on the other hand, is a command line tool, is free and works just as fine. The syntax is simple:

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

ILMerge doesn’t come with Visual Studio or an SDK, so you have to download and install it. For a more detailed description of ILMerge I also recommend this article on Code Project.