15

I'm sorry in advance for the, not so clear, title.

I've encountered a strange behavior in Visual Studio (2010).

Lets say that I have three projects in my solution: A, B and C.

A has a reference on B

B has a reference on C

C has a reference on an assembly (log4net.dll)

All of which are configured to Copy Local True.

I'm responsible for project A and two other developers are responsible for project B and C.

Project B is using several (static) methods that reside in project C in one of its classes. I'm using other classes from B that are not using anything from C.

When I built the solution (project A is configured as the main project), I expected to see the results of C and its referenced assemblies in the output folder of project A. What actually happened was that the results of C were copied to the output folder of B but were absent in the output folder of A.

It took me some time to figure out that the reason for this was that A is not using anything from C (directly or indirectly).

So the question is: is it a built in optimization feature of Visual Studio or am I doing something wrong?

Michael
  • 1,209
  • 2
  • 12
  • 25
  • Yes, MSBuild definitely knows how to do this. Lots of programmers have solutions with 10+ projects, they would work rather miserably if that feature didn't work. The info in your question doesn't give any hint what might be wrong, change the MSBuild verbosity to "Diagnostic" to get a detailed trace. Since you just got started on getting these projects together, not actually *using* a reference is the simple explanation. – Hans Passant Jan 08 '14 at 14:15
  • 1
    @HansPassant: Lots of programmers do have solutions with 10+ projects, but that doesn't automatically mean one of them references all of the other ones in a chain of explicit references. – O. R. Mapper Jan 08 '14 at 14:27
  • That's exactly the point of course. It is easy if these chains exist, they almost never do in real solutions. But everything still gets copied correctly. – Hans Passant Jan 08 '14 at 14:39
  • @HansPassant Thanks, the thing is that one can use project B independently of A. I was hoping to deploy A and B together and save some space. But B needs C to run independently so I'm unable to achieve this. – Michael Jan 09 '14 at 05:51
  • 1
    You can go through this [link](http://stackoverflow.com/questions/280751/what-is-the-best-practice-for-copy-local-and-with-project-references ).Could be helpful to you. – Raman Jan 09 '14 at 08:20
  • @Raman Thanks! It is a helpful post. However, I don't want to output all the binaries of the solution to one folder. – Michael Jan 09 '14 at 13:21

1 Answers1

3

Yes, it's a feature. If you don't use any of the types from the referenced assembly, it doesn't get copied.

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156