简体   繁体   English

如果给定的程序集是正确的,CLR如何知道?

[英]How does the CLR know which if the given assembly is the correct one?

If we have a .NET executable that's using a .NET library, how does the CLR ensure you are using the correct version of the dll? 如果我们有一个使用.NET库的.NET可执行文件,那么CLR如何确保您使用正确版本的dll? CLRwise what is considered be the "correct dll version", to start with? CLRwise什么被认为是“正确的dll版本”,从一开始?

Does it only look at the version? 它只看版本吗? Looks also at the build-time(?). 看一下构建时间(?)。 Maybe it looks at an hash or something? 也许它看起来像哈希什么的?

Thanks 谢谢

You may start to learn about .NET versioning, 您可以开始了解.NET版本控制,

http://msdn.microsoft.com/en-us/library/51ket42z(VS.71).aspx http://msdn.microsoft.com/en-us/library/51ket42z(VS.71).aspx

它采用编译期间使用的一个,由完全限定名称标识 - 不仅包括程序集名称,还包括完整版本信息和数字签名指纹(如果有)。

The other answers already cover the essence of it. 其他答案已经涵盖了它的本质。

Basically, the Framework checks for assembly name, version, and signature of an assembly to find a match. 基本上,框架检查程序集的程序集名称,版本和签名以查找匹配项。
The name and version (and more stuff!) you can set from code (AssemblyVersion attributes), and you can easily sign it with the help of VS, too. 您可以从代码(AssemblyVersion属性)设置名称和版本(以及更多内容!),您也可以在VS的帮助下轻松签名。

The signature involves creating a .pfx file (VS will generate one for you), and checking the "sign assembly" in the build settings. 签名涉及创建.pfx文件(VS将为您生成一个),并检查构建设置中的“签名程序集”。 This will ensure that more than one assemblies can coexist with the same name and version. 这将确保多个程序集可以使用相同的名称和版本共存。
(So if two companies accidentally created two things with the same name, you can still use them together.) (因此,如果两家公司意外地创建了两个具有相同名称的东西,您仍然可以一起使用它们。)

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

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