[英]Why does visual studio copy the DLLs/EXEs into the referenced projects build folders in c#?
Say I have four projects:假设我有四个项目:
ABCD A B C D
such that A references B, B references C and C references D. A引用B,B引用C,C引用D。
It appears in visual studio (2017) that building A also triggers a build in B, C, D, as is expected.正如预期的那样,在 Visual Studio (2017) 中,构建 A 也触发了 B、C、D 中的构建。 It only builds them once.
它只构建一次。 However, it seems the build copies the DLLs into each projects bin directory, leaving the directory structure (assuming building in Debug mode) looking something like this:
但是,构建似乎将 DLL 复制到每个项目的 bin 目录中,使目录结构(假设在调试模式下构建)看起来像这样:
A -> bin -> Debug -> A.exe, B.exe, C.exe, D.exe A -> bin -> 调试 -> A.exe、B.exe、C.exe、D.exe
B -> bin -> Debug -> B.exe, C.exe, D.exe B -> bin -> 调试 -> B.exe, C.exe, D.exe
C -> bin -> Debug -> C.exe, D.exe C -> bin -> 调试 -> C.exe, D.exe
D -> bin -> Debug -> D.exe D -> bin -> 调试 -> D.exe
This seems to imply that there is an O(n^2) where n is the number of projects (and they references each other like so) in terms of the number of executables/dlls copied .这似乎意味着有一个 O(n^2) ,其中 n 是项目的数量(它们像这样相互引用)就复制的可执行文件/dll 的数量而言。 This results in terrible scaling of the build time versus the number of projects.
这导致构建时间相对于项目数量的可怕缩放。 However having more projects becomes very necessary for increased granularity of files.
然而,为了增加文件的粒度,拥有更多的项目变得非常必要。
In the worst case, for n projects, adding another project results in (n + 1) extra file copies, using the (1 + 2.. + n) = (n(n+1))/2 formula.在最坏的情况下,对于 n 个项目,使用 (1 + 2.. + n) = (n(n+1))/2 公式添加另一个项目会导致 (n + 1) 个额外的文件副本。
Why does visual studio do this?为什么visual studio会这样做? Why not just copy only to A's bin directory?
为什么不只复制到 A 的 bin 目录? The only advantage I see to the current approach is that you can run DLLs/EXEs in the bin folders of B, C and D.
我认为当前方法的唯一优点是您可以在 B、C 和 D 的 bin 文件夹中运行 DLL/EXE。
Looks like this behaviour can be turned off.看起来可以关闭此行为。 The name for this is the copylocal property in visual studio.
它的名称是 Visual Studio 中的 copylocal 属性。 If you turn this off, then you are now responsible for copying the DLLs manually to where an output folder (for example, via a custom MSBuild step).
如果关闭此功能,则您现在负责将 DLL 手动复制到输出文件夹的位置(例如,通过自定义 MSBuild 步骤)。
These questions deal with it well:这些问题很好解决:
What is the best practice for "Copy Local" and with project references? “复制本地”和项目引用的最佳实践是什么?
Best practices for large solutions in Visual Studio (2008) Visual Studio 中大型解决方案的最佳实践 (2008)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.