2

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?

antonijn
  • 5,702
  • 2
  • 26
  • 33
Ziv
  • 2,755
  • 5
  • 30
  • 42

6 Answers6

4

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

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
1

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.

Adam K Dean
  • 7,387
  • 10
  • 47
  • 68
1

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.

adpmatos
  • 69
  • 7
1

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?

  1. add a new Class Library project with a unique name, say ClassLibrary1, to the solution

  2. in Build page of its project settings, config Output path to application output path

  3. in Build Events page, add the following line to Post-build event command line block:

    del "$(TargetPath)"
    
  4. copy external DLLs to its folder and add them to references of ClassLibrary1

  5. set Copy Local to true of all added references

  6. set Project Dependancies of other projects to it, check ClassLibrary1

  7. add references of other projects, from the path the DLLs were put in ClassLibrary1

  8. set Copy Local of all these added DLLs in other projects to false

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.

Ken Kin
  • 4,503
  • 3
  • 38
  • 76
0

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.

djechlin
  • 59,258
  • 35
  • 162
  • 290
0

Occam's razor says you should use the binaries if you don't need to modify the libraries.

Captain Kenpachi
  • 6,960
  • 7
  • 47
  • 68