Merge Multiple EXEs and DLLs into One Single File in .NETle

Mike Barnett at Microsoft Research has developed a great tool for merging multiple dll’s and/or exe’s in to one single file: ILMerge (download from here). ILMerge has been around for several years but this was the first time I tried it out.

You can either use it from a command line or automate so that it is executed every time you rebuild, as a post-build-event. You can also use it programatically but this I have not tried yet.

To use from the command line simply go to your .NET projects bin release folder and type:

“%PROGRAMFILES%\microsoft\ilmerge\ilmerge.exe” /t:exe /out:newfile.exe file1.exe file2.dll file3.dll

Newfile.exe is the filename of the single merged exe file you want created, and file1-3 are the filenames of the files you want to merge. Make sure file1 is your primary assembly. The t parameter is used to set output type: exe for Console app, winexe for Windows forms, librarys for DLL.

To automate in Visual Studio 2005, go into Project Properties (Right click your project in the Solution Explorer, Select Properties)
Select the Build Events tab and in the Post-build event command line enter:

“%PROGRAMFILES%\microsoft\ilmerge\ilmerge.exe” /t:exe /out:”$(TargetDir)newfile.exe” “$(TargetDir)file1.exe” “$(TargetDir)file2.dll” “$(TargetDir)file3.dll”

I have tried this using Windows Vista, Visual Studio 2005 and C# but I assume it will work equally well on other versions of Windows, VS and VB.NET or other .NET languages.

Thanks to these posts by Edward Tanguay and Can Erten.

Published
Categorized as .NET

8 comments

  1. Thanks, I could do it successfully but I had a problem with running the merged file! The problem is that by running the exe file of app the command window is opened too, which is really bad 🙂

  2. but how to avoid black screen problem afte ILMerge exe click.
    black screen open in background.

  3. Solve This Issue… & Enjoy It.

    “%PROGRAMFILES%\microsoft\ilmerge\ilmerge” /out:”$(TargetDir)NewBuild.exe” “$(TargetDir)ProjectExe.exe” “$(TargetDir)First.dll” “$(TargetDir)Second.Design.dll” “$(TargetDir)Third.Fonts.dll”

Leave a comment

Your email address will not be published. Required fields are marked *