tags:

views:

338

answers:

5

I am working in VS2008. I have a custom class library (CL1) which references another custom class library (CL2). This ends up having CL1 and CL2 in my release folder. Now the consumer of CL1 needs to include two dll's in the project which I think is not appropriate. I have strong feeling that there must be a way to achieve a single DLL solution. Is there a recommended (guideline-d) way of achieving this.

Merging CL1 and CL2 is not an option because CL2 is more common and referenced in multiple other projects/dll's . Am I missing some straight forward option? Or I need to embed CL2 as resource? How? Googled web but could not find the problem discussed anywhere.

A: 

Well, you could embed CL2 in CL1 and use the AssemblyResolve event to extract it when needed, by I would really not advice you to go that way. Simply include the DLL in the release, that is the normal way of distributing it, I would say.

Fredrik Mörk
Thanks for the response, Fredrik. Is it normal to distribute multiple dll's when the consumer of the dll is only going to use main dll classes. Isn't there a way to package multiple dll's in one. I understand that embedding dll's as binary files is not a good idea.
amrahs
+1  A: 

You could include the source code from CL2 as a linked files in the CL1 project, and use that as a way to avoid requiring the user to include multiple references. In my opinion, this is a bad idea.

If your class design really requires that your classes be split among multiple assemblies, and CL1 needs to refer to CL2, then its perfectly fine for the user to refer to multiple assemblies -- especially since, as you say, the assemblies serve different purposes.

If the user is only using classes from CL1, then they will not need to add multiple assemblies as references. However, if CL1 refers to CL2, CL2 will always be copied along with CL1, even if the reference to CL2 isn't explicit.

Nader Shirazie
I appreciate ur answers. My concern here is that CL2 is like an external dll for our department we can only reference it. Now, CL2 refers to CL1 internally only and consumer of CL1 has nothing to do with CL1 - apparently. I could not understand you last sentence "...CL2 will always be copied..." - do you mean automatically? I could not get it.
amrahs
correction - I appreciate ur answers. My concern here is that CL2 is like an external dll for our department we can only reference it. Now, CL2 refers to CL1 internally only and consumer of CL1 has nothing to do with CL2 - apparently. I could not understand you last sentence "...CL2 will always be copied..." - do you mean automatically? I could not get it.
amrahs
I meant that if you are creating CL1 which has a reference to CL2, then CL2 ends up in your build output. Your user will refer to CL1, which will copy CL1 into their build directory. CL2 will automatically get copied as well, since CL1 requires it, even if the user does not specifically add a reference to CL2.The only time where the user must add CL2 as a reference is if you have classes from CL1 inheriting from classes in CL2, or using classes as as method parameters, etc... is that the case?
Nader Shirazie
hmmm...looks ok when this all is done in the same development network. If I send the dll on external computers - I will have to send two dll's.
amrahs
Normal practice is generally to include all the build output stuff (both assemblies in this case). The fact that your assembly has dependencies isn't a terrible thing. What happens if your assembly takes on other dependencies as functionality gets added (or is this not a concern)?
Nader Shirazie
A: 

I believe this question may give you the answer you're looking for:

http://stackoverflow.com/questions/424032/how-to-link-a-dll-statically

richardtallent
Ours are both C# libs. I could not find way to link the dll statically in the answer and not sure whether it solves the problem. Thanks anyways.
amrahs
+4  A: 

Yes you can do it manually before releasing your product using ILmerge. More details can be found here at codeproject and on Brad McCabe's blog.

TheVillageIdiot
+1 never used this, but sounds promising
Nader Shirazie
Me too. I am going to do some more research on this.
amrahs
Here's a link to Brad's MS Research page which may be useful too- http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx
RichardOD
besides ILmerge you can also use ilasm to strong name prebuilt assemblies. For more information read this: http://www.andrewconnell.com/blog/archive/2004/12/15/772.aspx
TheVillageIdiot
A: 

Thanks to you all guys. I am, for now, thinking of using ILMerge. Let you know if I stumble upon any better way.

amrahs