Another hidden .Net Tool usage basics: ilMerge
Ilmerge is a great utility for any .net developer. What it does is basically merge the assemblies. Let’s say you have three dll and one exe file, you can just merge those 4 files to 1 file using ilmerge.
As a matter of fact, it is easy to use, you don’t need any recompilation or any other modification. You don’t need to provide installers since there is only one file.
Ilmerge exists in two versions one for .Net 1.1 and the other is .Net 2.0
Basic Usage
Usage: ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysig
n]] [/internalize[:filename]] [/t[arget]:(library|exe|winexe)] [/closed] [/ndebu
g] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] [/pu
blickeytokens] [/wildcards] [/zeroPeKind] [/allowDup:type]* /out:filename <prima
ry assembly> [<other assemblies>...]
Although the help explains very well, here is the usage.
C:\Program Files\Default Company Name\ILMergeBinaryDistribution7>Ilmerge /t:exe
/out:outputfile.exe file1.exe file2.dll
/t us used for the output of the file, exe is for a console application, winexe is for windows forms application and library is for the dlls.
/out is for the name of the output file.
the last parameters are the assemblies to be compined. Attention here is that the first one should be the exe one instead of the class library, becuase it merges the following files to the first file.
Advanced Usage
ILmerge is also usable as a class library for your project. What you need to do is to add the ilmerge executable as a reference and use the namespace of it to do some tasks. The class library is very similar to the console commands.









ILMerge is helpfull in some scenarios, but with others it can be dangerous.
For example - if you merge 2 assemblies with the same non public type on both - it will work but will change the name of the type.
is it a problem? yes if you use reflection…
and you can end up with multiple instance of a singleton too.
don’t forget the memory footprint of the merged assembly.
so do use this tool, but only after you understand the implications.
read more on Referencing different versions of an assembly - Part 1 (ILMerge)
7 January 2008, 11:04 am