简体   繁体   English

构建项目时,“复制本地”在 Visual Studio 中究竟是如何工作的

[英]How exactly does "Copy Local" work in Visual Studio while building the project

Today I had a closer look at the "Copy Local" property of assembly references in Visual Studio 2019. After a few experiments with unexpected results I set out to learn as much as possible about how the property works.今天,我仔细研究了 Visual Studio 2019 中程序集引用的“Copy Local”属性。经过几次实验并获得了意想不到的结果后,我开始尽可能多地了解该属性的工作原理。 Even SO, it appears to me, does not have all the answers, so here is my attempt at self-answering the question:在我看来,即使是这样,也没有所有的答案,所以这是我自我回答问题的尝试:

How exactly does the "Copy Local" property of an assembly reference work in Visual Studio?程序集引用的“Copy Local”属性在 Visual Studio 中究竟是如何工作的? And does the project use the assembly copied to the bin folder every time or does it use the assembly from the GAC?项目是否每次都使用复制到 bin 文件夹的程序集,还是使用 GAC 中的程序集?

"Copy Local" when set to true ensures that the dll for the assembly reference is added to the referencing project's bin folder so that it's available at the run time. “复制本地”设置为 true 时可确保将程序集引用的 dll 添加到引用项目的 bin 文件夹中,以便它在运行时可用。 If the required dll is not found in the bin folder then, the one in GAC can be used.如果在 bin 文件夹中找不到所需的 dll,则可以使用 GAC 中的那个。 If even then, the dll is not found, we will encounter errors.如果即使这样,找不到dll,我们也会遇到错误。

If the same version of the dll exists in bin as well as GAC then, the one from GAC is used but if a different version is used and referenced in the project then the one from bin gets used.如果 bin 和 GAC 中存在相同版本的 dll,则使用 GAC 中的那个版本,但如果在项目中使用和引用不同的版本,则使用 bin 中的那个。 Similar question answered in Dll in both the bin and the gac, which one gets used? bin 和 gac中的Dll 中回答了类似的问题,使用哪个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM