Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine 2 or more c# assemblies into 1 library?

Tags:

c#

dll

I have 4 dlls. But I want to have 1 single dll which will contain the code from all 4 of these dlls. I tried to add a project and copy paste all of my existing code into one project, but I couldn't.

like image 416
Javidan Avatar asked Sep 13 '11 05:09

Javidan


3 Answers

You can use ILMerge utility

Or you can embed the dlls you want to merge as resources

Here the code sample:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
   using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
   {
      Byte[] assemblyData = new Byte[stream.Length];
      stream.Read(assemblyData, 0, assemblyData.Length);
      return Assembly.Load(assemblyData);
   }
};
like image 88
Artur Mustafin Avatar answered Nov 02 '22 14:11

Artur Mustafin


Have a look into ILMerge

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly.

like image 20
Luke Baulch Avatar answered Nov 02 '22 15:11

Luke Baulch


There is a tool from MS: ILMerge

like image 41
Hubi Avatar answered Nov 02 '22 15:11

Hubi