How to guarantee that a project has all references from the projects it references?

74 Views Asked by At

Consider a solution with many class library projects. Each of them has a bunch of NuGet packages installed, and there is a single unit tests project for each of these projects. Keeping in mind that the class library projects' references are configured to Copy Local = false, how can I make sure that the unit test project always has at least all references from the original project?

We've been bitten by this problem on a few occasions already. Out of nowhere, our nightly build fails due to missing dlls, and when we check what happened, it's usually that someone added a new package or reference to a project but did not install the same reference in the unit tests project. That problem tends to not manifest itself because in a dev machine, each project copies it's outputs to a separate folder. When building in TFS though, MSBuild is overridden and all outputs are placed on the same folder.

We are using the Copy Local = false strategy on everything that doesn't need to be directly executed (that is, only test projects and web applications are configured to copy local all references). This was done to avoid unnecessary copies of dlls and speed up the build process. By using Copy Local = false, we are required to explicitly add all references to each project, because they are not copied from referenced projects automatically. For unit test projects, this usually means that our packages.config file in the tests project contains all packages from the original project, plus test specific dlls like mocking frameworks and the like.

Personally, I like needing to specify all references explicitly, because it makes it easier for someone to see what is happening and what depends on what more clearly. We have had problems in the past with the default Copy Local = true too, so I'm not very fond in changing it back to that. But once in a while we stumble on a problem that relates back to someone not adding the required references.

Can I enforce this in some way, so that it would not be possible to not have all references from a dependent project in a given project? Ideally, I'd like for it to be a compilation error, but any kind of enforcement would be beneficial. It would be very cool if every project in a solution behaved like a NuGet package when referencing each other: with NuGet packages, you are always sure that all references are correct, because dependencies are explicitly stated in the nupkg and added to any project that adds the original package.

0

There are 0 best solutions below