views:

257

answers:

3

I have been wondering what are best practices when it comes to referencing 3rd party assemblies. A while ago I asked a question "Dependencies and references: what exactly should I reference" and received something to think about but I am not completely convinced. I have a 3rd party assembly needed for building my project and according to what I have read so far I should only reference assemblies needed for building my project. This leaves the problem of the runtime dependencies of the 3rd party assembly. If I reference those too the list of references becomes huge (as there are several dependencies) and includes a lot of assemblies I have no clue what do and are really not related to my project. Also I want to avoid using public methods in any of those and just use the main 3rd party assembly. How can I go about doing this in a decent way? Any help is appreciated as I am quite confused.

To give an idea of what I am dealing with here is the 3rd party library uses hibernate and log4net along with office interop assemblies.

Thanks.

+2  A: 

If i have to deal with libraries that aren't registered in the GAC, I use the following method:

  • Make a folder "Libs" with all third party libraries and their dependencies in it
  • Reference the ones I need
  • Create a post-build action that copies all the files in the "Libs" folder to the "bin/debug" (or release) folder

If you don't know the dependencies, you can use Dependency Walker.

Vincent Van Den Berghe
How do you deal with shared libraries? Say if you have 3 projects that are part of the same solution and they share libraries. Then you have a 3rd party library (along with dependencies) used in one of them. Do you have lib folder in each of the projects with libs copies in each?
Fadeproof
And by this "Libs" folder do you mean that you have the Libs folder in each project directory?
Fadeproof
There is only 1 'Libs'.Solution folder|_ Libs|_ Project1|_ Project2|_ Project3|_ binProject1, Project2 and Project3 all reference the same library in 'Solution folder\Libs'.
Vincent Van Den Berghe
This is what I do, but you don't need a post build action, just set "Copy Local" to true on the properties of the reference.
Lou Franco
You also need the libraries on which the referenced libraries depend.
Vincent Van Den Berghe
That is exactly the point I was asking about - as vincent points out you also need the libraries on which the referenced libraries depend.
Fadeproof
+2  A: 

An alternate I've been using on many (C#) projects is:

  • Make a "Bin" folder in the solution directory (same level as the project directories)
  • Make the output of all projects ../Bin instead of bin/debug or bin/release
  • Put whatever files that are not a result of the build in "Bin", including library dependencies, certain data files or whatever, depending on the project
  • Contents of "Bin" also goes to source control (without the build output, of course)
  • Whatever libraries directly referenced by your projects goes to a "References" or "Libs" folder (sometimes I've also tried putting them in Bin too, but in this case you need to remember to disable copying of references to output dir when adding the reference to your project, which becomes tedious on large projects)

Not really sure if it's a good solution, but has worked for me till now.

Dan C.
+1  A: 

You can also use NDepend to know and control exactly what you use from tiers library. I wrote an article about this Controlling the usage of libraries

Patrick Smacchia - NDepend dev