Have you ever written a small, single purpose application? Mine usually start out simple, then I want to add more features to make it better for the user.

Let’s say we’re building a utility to test network speed. We want our application to read from a database and write to the Windows event log. We already have dll’s to help with database access and the Windows event logs, so we’ll reference them in our utility. Now we have three files (one exe and two dll’s). Not bad, we can handle three files.

If we are giving this application to other users, we need to come up with how we want to deploy our three files. Luckily, we have a few options. We could create an application installer. There is a bit of overhead here, especially if we do not already have a build pipeline in place. There is also a stigma around “installing” software, especially if you are working on someone else’s computer. Building an install might not be the best options for our application.

We could zip all three files and explain to our users that all three files need to exist in the same directory for the application to work. That’s not a bad plan, but eventually one person will move a file and the application will crash. This option feels like we are asking for trouble.

Fear not, there is another option! Introducing ILMerge – a utility that can merge our exe and two dll’s into one exe. Using ILMerge is simple, all we need to do is tell ILMerge what kind of file we are making, our output name, source files and our .NET framework target version. ILMerge will take care of the rest.

Example usage:

“C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe” /target:winexe /out:MyTestAp
p.all.exe MyTestApp.exe CommonDatabaseMethods.dll CommonLoggingMethods.dll /targetplatform:”v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.

Running the above command will merge MyTestApp.exe, CommonDatabaseMethods.dll and CommonLoggingMethods.dll into a new file named MyTestApp.all.exe. MyTestApp.all.exe will be a Windows executable with GUI and target the .NET 4 runtime. We can give MyTestApp.all.exe to our users – no installer and no messy files to keep track of! Our application and references are all baked into one file!

ILMerge works for WinForms and console applications, but was not designed for WPF applications.

ILMerge is available from Microsoft here: https://www.microsoft.com/en-us/download/details.aspx?id=17630

Source code and documentation are available on the github page https://github.com/Microsoft/ILMerge

UPDATE: It appears that ILMerge can handle WPF projects. More details after I test 🙂