When using an open source library in a project (for example SharpPcap or FakeItEasy) should we add the source code to the solution or compile against the DLLs and put them in a directory in the solution?
-
1if you are not planning to alter the library source code, use the DLL directly. – xlecoustillier Feb 24 '13 at 11:17
6 Answers
You should compile using the binaries.
The reason is very simple: your project and third-party libraries are different projects and compiling others' libraries during your own build process may introduce unnecessary complexity and project dependencies.
Some libraries require you to have some tools and plug-ins installed in your environment.
Instead of including the open source code in the build process, usually I have a dependencies or lib directory in the root of the Visual Studio solution with both the binaries and the source code. When I want to debug third-party code I just open another instance of Visual Studio and I attach there the debugger to the whole process.
Think some third-party open source libraries are very fat and maybe your own code base is small: since you add a lot of source code, your build process will delay a lot of because you just added useless stuff (code, plug-ins....).
I prefer the principle of delegating the build process to the author of the library and, in my case, I see myself as a consumer of such library: I don't need to recompile it everytime.
Ah, and if you're planning to modify the source code, the best practice should be contacting the author and sending to him/her the patches so he/she can include it in the official distribution. If not, you know: everytime the author releases a new version, you'll have the extra job of merging the new source code with your own changes...

- 63,804
- 18
- 124
- 206
I would say use the binaries provided as the source code might not be stable if you're getting it at it's latest version. But if they are providing versioned binaries then they have most likely been tested and are stable.
It also depends on if you're just using it out of the box or whether you want to modify it.

- 7,387
- 10
- 47
- 68
Usually I compile against the binaries. I have a folder vendor/libs on my solutions, or I just use NuGet, and compile againest the Dlls.
But, sometimes I need to debug the open source library, when something is not happening as expected. And just then, I link with the source code (just for debugging).
When going to production, I use the binaries, because the code is already well tested.

- 69
- 7
I would think neither.
Following are the reasons do NOT put the source code:
- developers might modify the code carelessly
- libraries usually subject to change
And following are the reasons DO include DLLs to the solution:
- makes deploying be more easily
- reduce the chances of using incompatible version of libraries
- reduce the chances of missing references
So, how to?
add a new
Class Library
project with a unique name, sayClassLibrary1
, to the solutionin
Build
page of its project settings, configOutput path
to application output pathin
Build Events
page, add the following line toPost-build event command line
block:del "$(TargetPath)"
copy external DLLs to its folder and add them to references of
ClassLibrary1
set
Copy Local
totrue
of all added referencesset
Project Dependancies
of other projects to it, checkClassLibrary1
add references of other projects, from the path the DLLs were put in
ClassLibrary1
set
Copy Local
of all these added DLLs in other projects tofalse
Thus, the project ClassLibrary1
be a central control of the external libraries of your solution. Everytime you Rebuild Solution
, ClassLibrary1
copies the latest DLLs added to its References
to the application output folder, and deletes the DLL it generated itself named ClassLibrary1.DLL
. And the application at either compile time or runtime would use the same version of DLLs, you don't need to do extra deploying or check for each deployment everytime you release your application.

- 4,503
- 3
- 38
- 76
Binaries:
- more stable unless you are mindful of pulling a release version of source
- easier
Source:
- can modify
- can debug use of APIs by stepping directly into source
That last point is often important, so be prepared to download and open the source in your IDE even if you started with just the binary, especially if the library you are using is young or ill-tested.

- 59,258
- 35
- 162
- 290
Occam's razor says you should use the binaries if you don't need to modify the libraries.

- 6,960
- 7
- 47
- 68