开发者

Can you bundle dlls together?

开发者 https://www.devze.com 2022-12-16 00:05 出处:网络
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).

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 use开发者_如何转开发s 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.


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.


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...


You can use ILMerge to combine assemblies into one DLL.

https://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx


You can either use an IL merging tool, or install ToolsDLL.dll in the GAC.

Also if you look at the output of App_A, ClassA.dll is already there, that's where it's looking for ToolsDLL.dll.

0

精彩评论

暂无评论...
验证码 换一张
取 消