6

Perhaps I am missing something obvious here but...

I have built a reusable generic C# class library project say (A.dll) which references 3 other assemblies say (B.dll, C.dll and D.dll)

However if I want to reuse my component A.dll in another project I still have to include the references to B.dll, C.dll and D.dll.

Is there any way you can configure A.dll to build all its dependencies into the A.dll so I don't have to include the other 3 assemblies?

Cheers

  • There is little difference between shipping 4 assemblies or 1. And with separate assemblies you keep all the versioning/signing intact. – H H Feb 15 '10 at 10:55

2 Answers2

6

It's possible to merge assemblies, using the tool ILMerge:

C:\Program Files\Microsoft\ILMerge\ILMerge.exe /target:library /out:abcd.dll a.dll b.dll c.dll d.dll"

This will merge the dlls a, b, c and d into abcd.dll. It will also merge the debugging symbols but not the XML documentation.

Also you'll have to reference the dll itself in new projects and not the respective projects. An exception to this is if you merge libraries into an executable, in that case you can reference the respective libraries/projects because they will be loaded with the executable.

The Mono Project also has a tool for this, called mkbundle.

Also available is ILRepack, which aims to be compatible with ILMerge, but is FLOSS.

Bobby
  • 11,419
  • 5
  • 44
  • 69
  • Yes, you can do it this way. But you shouldn't (in general). – H H Feb 15 '10 at 10:54
  • You're messing up version and signature info. For a perceived gain. – H H Feb 15 '10 at 14:22
  • @Henk Holterman: Ahhh...I see. But as far as I know the version and signature of the main Assembly are preserved. But of course you're right, you should always be on the look out for that. Thanks for info. – Bobby Feb 15 '10 at 14:42
  • Thanks for the input on this. Cheers CueBall –  Feb 16 '10 at 11:05
0

This would be something like static linking of DLLs which works fine with native C++. As far as I know you cannot statically link assemblies in .NET code, thus you have to include all DLLs.

Simon Linder
  • 3,378
  • 4
  • 32
  • 49