<t>I'm not sure why it is different when building between Visual Studio and MsBuild, but here is what I have found when I've encountered this problem in MsBuild and Visual Studio.<br/>
<br/>
Explanation<br/>
<br/>
For a sample scenario let's say we have project X, assembly A, and assembly B. Assembly A references assembly B, so project X includes a reference to both A and B. Also, project X includes code that references assembly A (e.g. A.SomeFunction()). Now, you create a new project Y which references project X.<br/>
<br/>
So the dependency chain looks like this: Y => X => A => B<br/>
<br/>
Visual Studio / MSBuild tries to be smart and only bring references over into project Y that it detects as being required by project X; it does this to avoid reference pollution in project Y. The problem is, since project X doesn't actually contain any code that explicitly uses assembly B (e.g. B.SomeFunction()), VS/MSBuild doesn't detect that B is required by X, and thus doesn't copy it over into project Y's bin directory; it only copies the X and A assemblies.<br/>
<br/>
Solution<br/>
<br/>
You have two options to solve this problem, both of which will result in assembly B being copied to project Y's bin directory:<br/>
<br/>
- Add a reference to assembly B in project Y.<br/>
<br/>
- Add dummy code to a file in project X that uses assembly B.<br/>
<br/>
Personally I prefer option 2 for a couple reasons.<br/>
<br/>
- If you add another project in the future that references project X, you won't have to remember to also include a reference to assembly B (like you would have to do with option 1).<br/>
<br/>
- You can have explicit comments saying why the dummy code needs to be there and not to remove it. So if somebody does delete the code by accident (say with a refactor tool that looks for unused code), you can easily see from source control that the code is required and to restore it. If you use option 1 and somebody uses a refactor tool to clean up unused references, you don't have any comments; you will just see that a reference was removed from the .csproj file.<br/>
<br/>
Here is a sampl<br/>
<br/>
(Réponse tronquée)</t>