Click here to Skip to main content
12,299,086 members (50,992 online)
Click here to Skip to main content
Add your own
alternative version


106 bookmarked

Merging .NET assemblies using ILMerge

, 21 Jan 2005
Rate this:
Please Sign up or sign in to vote.
Shows how to merge multiple .NET assemblies to a single one using ILMerge.


As you know, traditional linking of object code is no longer necessary in .NET. A .NET program will usually consist of multiple parts. A typical .NET application consists of an executable assembly, a few assemblies in the program directory, and a few assemblies in the global assembly cache. When the program is run, the runtime combines all these parts to a program. Linking at compile time is no longer necessary.

But sometimes, it is nevertheless useful to combine all parts a program needs to execute into a single assembly. For example, you might want to simplify the deployment of your application by combining the program, all required libraries, and all resources, into a single .exe file.

A single project

If all parts of your program are written by yourself in the same language, you can obviously just add all source files to a single project. The result will be a single DLL or EXE containing all dependencies.

csc /target:winexe /out:Program.exe 
      MainProgram.cs ClassLibrary1.cs ClassLibrary2.cs

However, if your program is written in multiple languages or if you are using binary third party libraries, you are out of luck.

.NET Modules

The .NET compilers already contain options for exactly this. If you compile a project, there is an option to create a module, which is similar to an assembly but without a manifest file. You can then use the al.exe tool to combine some of these modules to a single assembly. This feature makes it possible to create a single assembly that contains multiple languages.

First, you would compile the program and the class libraries to netmodules using the module target. Then you can use the assembly linker al.exe to combine these modules to a single assembly.

csc /target:module /out:ClassLibrary1.netmodule ClassLibrary1.cs
vbc /target:module /out:ClassLibrary2.netmodule ClassLibrary2.vb
vbc /target:module /out:Program.netmodule Program.vb
al /target:winexe /out:Program.exe ClassLibrary1.netmodule 
                 ClassLibrary2.netmodule Program.netmodule

But unfortunately, this method only works if you have all the required parts of your program either as source code or as .NET modules. If you are useing a third party class library in assembly form, you are again out of luck.


Since a .NET module is basically just an assembly without an assembly manifest, it should be possible to convert an assembly to a .NET module, at least that is what I thought. When researching this on Google, I found a tremendously useful tool on Microsoft research called ILMerge. This little gem makes it possible to link multiple assemblies to a single one.

First, you would compile your libraries to DLLs and your program to an EXE referencing the DLLs. This is exactly what Visual Studio would do if you had multiple libraries and a program referencing these libraries, so there is no need to do this on the command line.

csc /target:library /out:ClassLibrary1.dll ClassLibrary1.cs
vbc /target:library /out:ClassLibrary2.dll ClassLibrary2.vb
vbc /target:winexe /out:Program.exe 
    /reference:ClassLibrary1.dll,ClassLibrary2.dll Program.vb

This will produce a normal .exe that requires the two DLLs in the program directory or in the global assembly cache to run.

Now you can link these parts to a single self-contained EXE, using ILMerge:

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

The nice thing about this is that you can also merge third party assemblies like commercial class libraries into your program. And you do not have to modify your build process. All you have to do is to merge the assemblies to a single EXE before deploying.


I found ILMerge tremendously useful, and I think that something like this should be a part of the .NET framework SDK. Maybe just enhance al.exe so that it can also link DLLs.

I have only scratched the surface of the .NET build process and the capabilities of ILMerge, and this article might contain many inaccuracies or even errors. But I found ilmerge.exe so useful that I just had to write about it.


  • ILMerge: The ILMerge utility from Michael Barnett of Microsoft Research.
  • ILMerge Task: A NAnt task for ILMerge.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Rüdiger Klaehn
Web Developer
Germany Germany
Rüdiger Klaehn works as freelance developer in the space industry. He is very interested in functional programming languages and hopes that .NET will lead to a more widespread adoption in the industry.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Lagkip14-Dec-12 4:13
memberLagkip14-Dec-12 4:13 
QuestionLinking assemblies AND .net framework into one assembly using FuZe Pin
Frank van Bokhoven20-Sep-12 3:10
memberFrank van Bokhoven20-Sep-12 3:10 
QuestionUse this Tool to merge Pin
KrishanGahlot13-Sep-12 23:54
memberKrishanGahlot13-Sep-12 23:54 
SuggestionILMerge Pin
Mast Avalons6-Dec-11 8:33
memberMast Avalons6-Dec-11 8:33 
GeneralRe: ILMerge Pin
Bartosz Wojcik27-Jan-12 4:15
memberBartosz Wojcik27-Jan-12 4:15 
GeneralMy vote of 5 Pin
Mast Avalons6-Dec-11 8:26
memberMast Avalons6-Dec-11 8:26 
GeneralMy vote of 2 Pin
hfrmobile28-Jun-11 10:13
memberhfrmobile28-Jun-11 10:13 
GeneralCompact Framework Pin
hfrmobile28-Jun-11 10:06
memberhfrmobile28-Jun-11 10:06 
GeneralMy vote of 5 Pin
User97023-Apr-11 5:47
memberUser97023-Apr-11 5:47 
GeneralIlmerge and WPF Pin
devvvy26-Jan-11 16:36
memberdevvvy26-Jan-11 16:36 
AnswerRe: Ilmerge and WPF Pin
jmix9024-Feb-11 22:38
memberjmix9024-Feb-11 22:38 
GeneralA point Pin
PIEBALDconsult12-Aug-10 3:30
mvpPIEBALDconsult12-Aug-10 3:30 
GeneralMy vote of 1 Pin
kitog9-May-10 23:42
memberkitog9-May-10 23:42 
GeneralFailed to run Pin
Tammam Koujan19-Jan-10 4:51
memberTammam Koujan19-Jan-10 4:51 
GeneralRe: Failed to run Pin
hfrmobile28-Jun-11 10:12
memberhfrmobile28-Jun-11 10:12 
GeneralILMerge GUI Pin
Lee.17-Oct-09 1:26
memberLee.17-Oct-09 1:26 
I've Written a (rough) GUI for ILMerge, but according to MS Research, it(ILMerge) can't be redistributed. By the way, I <3 ILMerge.
GeneralRe: ILMerge GUI Pin
qualityking4-Sep-10 9:00
memberqualityking4-Sep-10 9:00 
GeneralMerged DLL com registration Pin
William F8-Jun-09 5:17
memberWilliam F8-Jun-09 5:17 
QuestionHow do you merge all the assemblies in the bin folder using ILMerge using command line Pin
azamsharp24-Jul-08 5:07
memberazamsharp24-Jul-08 5:07 
GeneralWindows Mobile 6.0 Compatibility Pin
Mandeep Singh Sidhu23-Apr-08 1:31
memberMandeep Singh Sidhu23-Apr-08 1:31 
GeneralRe: Windows Mobile 6.0 Compatibility Pin
hfrmobile28-Jun-11 10:16
memberhfrmobile28-Jun-11 10:16 
GeneralCOM Pin
GAbirkan22-Dec-07 8:33
memberGAbirkan22-Dec-07 8:33 
GeneralRe: COM Pin
peejay0225-Apr-10 3:27
memberpeejay0225-Apr-10 3:27 
GeneralProblem after merging Pin
padhalni19-Feb-07 0:56
memberpadhalni19-Feb-07 0:56 
QuestionRe: Problem after merging Pin
a858410-Apr-07 7:56
membera858410-Apr-07 7:56 
AnswerRe: Problem after merging Pin
a858410-Apr-07 8:04
membera858410-Apr-07 8:04 
Questionmerging a bunch of DLLs of an ASP.NET project Pin
weareborg2-Dec-06 6:32
memberweareborg2-Dec-06 6:32 
GeneralLocalisation DLLs Pin
Douba29-Jun-06 0:49
memberDouba29-Jun-06 0:49 
GeneralRe: Localisation DLLs Pin
hfrmobile28-Jun-11 10:11
memberhfrmobile28-Jun-11 10:11 
GeneralGUI for ILMerge - Gilma Pin
Tomer Shalev2-Dec-05 10:27
memberTomer Shalev2-Dec-05 10:27 
GeneralThere is a product out there with UI for ILMerger Pin
Samar Aarkotti14-Oct-05 10:21
memberSamar Aarkotti14-Oct-05 10:21 
GeneralRe: There is a product out there with UI for ILMerger Pin
Frank Hileman29-Nov-05 6:58
memberFrank Hileman29-Nov-05 6:58 
Generalsimple question. Pin
Samar Aarkotti13-Oct-05 3:43
memberSamar Aarkotti13-Oct-05 3:43 
GeneralRe: simple question. Pin
hfrmobile28-Jun-11 10:09
memberhfrmobile28-Jun-11 10:09 
General3rd party control licenses after merge Pin
Drew Noakes6-Sep-05 4:29
memberDrew Noakes6-Sep-05 4:29 
GeneralRe: 3rd party control licenses after merge Pin
weiser_98@hotmail.com6-Feb-06 22:14
memberweiser_98@hotmail.com6-Feb-06 22:14 
GeneralRe: 3rd party control licenses after merge Pin
Bertrand Jobert5-Nov-07 10:13
memberBertrand Jobert5-Nov-07 10:13 
GeneralDotfuscator and ILMerge Pin
mceranski29-Aug-05 7:09
membermceranski29-Aug-05 7:09 
GeneralRe: Dotfuscator and ILMerge [modified] Pin
qjhsert14-Oct-06 22:27
memberqjhsert14-Oct-06 22:27 
Generalno output Pin
NewYoda12-Aug-05 22:21
memberNewYoda12-Aug-05 22:21 
GeneralRe: no output Pin
Drew Noakes6-Sep-05 4:35
memberDrew Noakes6-Sep-05 4:35 
QuestionHow to use this Pin
allenmpcx12-Aug-05 20:46
memberallenmpcx12-Aug-05 20:46 
AnswerRe: How to use this Pin
Drew Noakes6-Sep-05 4:38
memberDrew Noakes6-Sep-05 4:38 
GeneralVB.NET and Setup Projects Pin
AndrewChapman9-Aug-05 13:49
memberAndrewChapman9-Aug-05 13:49 
GeneralRe: VB.NET and Setup Projects Pin
dcoolidge12-Aug-05 12:39
memberdcoolidge12-Aug-05 12:39 
GeneralRe: VB.NET and Setup Projects Pin
AndrewChapman12-Aug-05 15:28
memberAndrewChapman12-Aug-05 15:28 
GeneralRe: VB.NET and Setup Projects Pin
__debug26-Aug-05 20:02
member__debug26-Aug-05 20:02 
GeneralILMerge Managed DirectX DLLs Pin
Dr_Lomax24-Jun-05 1:54
memberDr_Lomax24-Jun-05 1:54 
GeneralGreat, but... Pin
BurntSky26-Apr-05 7:27
memberBurntSky26-Apr-05 7:27 
GeneralIn Mono/Linux you have the mkbundle utility Pin
RafaelTeixeiraBR22-Feb-05 9:05
memberRafaelTeixeiraBR22-Feb-05 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 21 Jan 2005
Article Copyright 2005 by Rüdiger Klaehn
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid