Sometimes you have developed a simple utility tool that doesn’t need the directory structure of a full-blown application for resources and other configuration. However, this tool might have a couple of library dependencies. On the .NET platform this usually means that you have to distribute the .dll files for the libraries along with the executable (.exe) file of the tool.
Wouldn’t it be nice to distribute your tool only as a single .exe file, so that users don’t have to drag around a lot of files when they move the tool from one location to another?
In the C++ world you would use static linking to link library dependencies into the resulting executable. For the .NET platform Microsoft provides a command-line tool called ILMerge. It can merge multiple .NET assemblies into a single assembly:
PM> Install-Package ilmerge
The basic command line syntax of ILMerge is:
> ilmerge /out:filename <primary assembly> [...]
The primary assembly would be the original executable of your tool. It must be listed first, followed by the library assemblies (.dll files) to merge. Here’s an example, which represents the scenario from the diagram above:
> ilmerge /out:StandaloneApplication.exe Application.exe A.dll B.dll C.dll
Keep in mind that the resulting executable is still dependent on the existence of the .NET framework on the system, it’s not completely independent.
Graphical user interface
There’s also a graphical user interface for ILMerge available. It’s an open-source tool by a third-party developer and it’s called ILMerge-GUI, published on Microsoft’s CodePlex project hosting platform.
You simply drag and drop the assemblies to merge on the designated area, choose a name for the output assembly and click the “Merge!” button.