Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to package more than one .NET assembly in a dll?

I'd like to keep my components/assemblies clearly separated from a source code point of view but I also need in some circumstances (probably not relevant to expand) to package them in the same dll.

Is it possible to package a number of .NET assemblies in a single dll? If so, How?

IF possible, do you think it is a good idea? Why?

Any help appreciated!

like image 956
JohnIdol Avatar asked Aug 27 '09 10:08

JohnIdol


2 Answers

Check out this article : Merging .NET assemblies 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.

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

.

ilmerge /target:winexe /out:SelfContainedProgram.exe 
        Program.exe ClassLibrary1.dll ClassLibrary2.dll
like image 65
Andreas Grech Avatar answered Nov 27 '22 21:11

Andreas Grech


ILMerge can merge two assemblies into one.

See here for information (the examples are for cross language, but it will work whatever tools built the assemblies).

Obviously any dependencies on the individual assemblies (pre-merge) will need to be updated/redirected.

like image 37
Richard Avatar answered Nov 27 '22 23:11

Richard