如何设置“复制本地依赖项”在 C# 项目中 [CopyLocal 问题]
我有一个名为 A.dll 的程序集,它具有对名为 B.dll 的程序集的项目引用。引用 B.dll 的程序集具有对 C.dll 的二进制引用。
A.dll--> B.dll --> C.dll
我已将 A.dll 中 B 的“复制本地”设置为 true,并将 B.dll 中 C.dll 的“复制本地”设置为 false。
无论如何,当我构建 A.dll 时,我在结果文件夹中以 C.dll 结尾。为什么不考虑 B.dll 到 C.dll 的“复制本地”值?
谢谢
I have an assembly called A.dll that has a project reference to an assembly called B.dll. The assembly referenced B.dll has a binary reference to C.dll.
A.dll --> B.dll --> C.dll
I've set at A.dll the "Copy Local" of B to true and I've set at B.dll the "Copy Local" to false of C.dll.
Anyway when I build A.dll I end with C.dll at the result folder. Why is not taken into account the "Copy Local" value of B.dll to C.dll?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为 msbuild 能够找到 c.dll。它对 B 项目的复制本地设置一无所知。它只是查看 b.dll 元数据中的 .assemble 指令,并发现 c.dll 是一个依赖项。如果它可以找到 c.dll 那么它就会复制它。如果它找不到它,那么什么也不会发生,也没有抱怨。
奇怪的部分和您的解决方案是 c.dll 与 b.dll 存在于同一目录中。它是怎么到达那里的?只要阻止它被复制到那里,它也不会被复制到 A 构建目录。否则,你期望它如何运行是相当模糊的。
That's because msbuild was able to find c.dll. It doesn't know anything about the copy local setting of the B project. It simply looks at the .assembly directives in the metadata of b.dll and sees that c.dll is a dependency. And if it can find c.dll then it will copy it. If it cannot find it then nothing happens, no complaints either.
The odd part, and your solution, is that c.dll is present in the same directory as b.dll. How did it get there? Just stop it from getting copied there and it won't get copied to the A build directory either. It is otherwise quite murky how you'd expect this to ever run.
这是因为
CopyLocal
将引用的程序集及其依赖项复制到输出文件夹,除非引用的程序集或依赖项驻留在 GAC 中。由于您在引用的
B
上设置了CopyLocal
,因此B
及其依赖项C
都将被复制到A
的输出文件夹,即使您没有在B
项目中引用的C
上设置CopyLocal
。请注意,如果您构建
B
,C
不会复制到B
的输出文件夹。如果您希望将
B
复制到A
的输出文件夹,但不希望C
发生同样的情况,一种解决方案是将C
放入 GAC 中。That's because
CopyLocal
copies the referenced assembly and its dependencies to the output folder, except if the referenced assembly or dependency resides in the GAC.Since you set
CopyLocal
on the referencedB
, bothB
and its dependencyC
will be copied toA
's output folder, even if you did not setCopyLocal
on the referencedC
in theB
project.Note that if you build
B
,C
is not copied toB
's output folder.If you want
B
to be copied toA
's output folder but don't want the same to happen toC
, one solution would be to putC
in the GAC.