Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you bundle dlls together?

I have a class library project that i have made. Let's call it ClassA. In ClassA i need to access some tools that reside in dll (ToolsDLL.dll).

In ClassA I have added ToolsDLL.dll to the project and selected the ToolsDLL.dll file to Copy To Output directory ALWAYS. So that library builds and compiles just fine and in the output directory i see ClassA.dll along with ToolsDLL.dll

Next, I want to write an application, say App_A that uses the methods in ClassA. So, in my App_A project, I added a reference to ClassA.dll so that I can access it's namespace. All is well and good, it build/compiles.

The problem is as soon as I run App_A and it gets to a point where ToolsDLL.dll needs to be used it throws an exception "Unable to Load ToolsDLL.dll. I don't understand how it is possible that it can't find that dll because it is in the same directory as ClassA.dll.

I found that if i put ToolsDLL.dll in the output directory of App_A it works just fine. Is there any way around that? Is there any way that ToolsDll.dll can be somehow bundled with ClassA.dll. The reason is that my customers will be writing their own applications similar to AppA and it would be nice if they only had to reference one file in their project and not multiple.

like image 320
PICyourBrain Avatar asked Jan 05 '10 16:01

PICyourBrain


People also ask

Can you combine DLL files?

Yes, it is impossible to merge dll files; there is no tool to do it and it cannot be done manually either. You must modify the source code.

Can a DLL contain another DLL?

You can certainly embed another DLL as a resource and extract and load it at runtime if that's what you need.

How can you tell if two dlls are the same?

You can use . NET Reflector to Disassamble the dll and compare it to the last code change you made to see if they are the same. If they are they you know that they are based on the same code.


2 Answers

There's a tool from Microsoft called ILMerge. It will probably do what you want, bundling several assemblies into one file.

P.S.: Another, fairly frequently used solution to your problem would be to add a post-build event to your application's solution/project that copies the required ToolsDLL.dll over to the output directory? Something along the line of:

xcopy /y /d $(SolutionDir)\lib\ToolsDLL.dll $(OutputDir)\ToolsDLL.dll

(Sorry if I get some of it wrong, I'm typing this from my memory.)

Of course, your customer would also have to do this. But then again they've probably done this before.

like image 87
stakx - no longer contributing Avatar answered Oct 02 '22 06:10

stakx - no longer contributing


Have you added the DLL to the project, or have you actually added a reference to it? You should do the latter, then this sort of thing is taken care of automatically for you. It sounds like you have added the actual file to the project files, and set it to copy.

If you do definitely want a single file approach, then accept the others' suggestions of ILMerge obviously...

like image 30
David M Avatar answered Oct 02 '22 05:10

David M