如何设置“复制本地依赖项”在 C# 项目中 [CopyLocal 问题]

发布于 2024-10-12 12:48:43 字数 295 浏览 4 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶舞 2024-10-19 12:48:43

那是因为 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.

稀香 2024-10-19 12:48:43

这是因为 CopyLocal 将引用的程序集及其依赖项复制到输出文件夹,除非引用的程序集或依赖项驻留在 GAC 中

由于您在引用的 B 上设置了 CopyLocal,因此 B 及其依赖项 C 都将被复制到 A 的输出文件夹,即使您没有在 B 项目中引用的 C 上设置 CopyLocal

请注意,如果您构建 BC 不会复制到 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 referenced B, both B and its dependency C will be copied to A's output folder, even if you did not set CopyLocal on the referenced C in the B project.

Note that if you build B, C is not copied to B's output folder.

If you want B to be copied to A's output folder but don't want the same to happen to C, one solution would be to put C in the GAC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文