Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个引用 .NET DLL 的 C# 应用程序。 如果这个 DLL 在我的应用程序bin目录和 GAC 中都存在,那么 CLR 在运行时会选择哪一个?如果 GAC 有最新版本,是否会使用该版本而不是 中的版本bin?
bin
以及如何强制 CLR 始终使用我的bin而不是 GAC 中的那个?
根据 MSDN:
CLR 检查全局程序集缓存、配置文件中指定的代码库,然后检查应用程序的目录和子目录。
那么,这是否意味着它首先会调查 GAC? 谢谢。
您可以强制 CLR不使用 GAC 中的程序集副本,因为它不在 GAC 中。通过重命名 DLL 或在项目中引用它之前更改其 [AssemblyVersion] 即可轻松实现。跳过它会调用讨厌的运行时异常,也就是所谓的 DLL Hell。