.NET 如何知道 dll 是相同的?
我写了一些这样的示例代码,所有输出都是相同的,这对我来说很奇怪,
我想如果 assembly1 与 assembly2 相同是有意义的,因为程序集信息是相同的(例如名称、程序集版本、GUID)等)
但是,我更改了程序集信息并重新编译了 SampleCodedFormula.dll(然后将其重命名为 Changed-assemply-info-and-recompile-SampleCodedFormula.dll),令人惊讶的是, assembly3 输出仍然与 assembly1 相同。
assembly1,2,3 是从相同的代码库编译的。
谁能告诉我为什么会有这样的行为?这对你来说有意义吗?
var domain = AppDomain.CurrentDomain;
var assembly1 = domain.Load(AssemblyName.GetAssemblyName("c:\\SampleCodedFormula.dll"));
Console.WriteLine(assembly1.CodeBase);
Console.WriteLine(assembly1.GetExportedTypes()[0]);
var assembly2 = domain.Load(AssemblyName.GetAssemblyName("c:\\Copied-From-SampleCodedFormula.dll"));
Console.WriteLine(assembly2.CodeBase);
Console.WriteLine(assembly2.GetExportedTypes()[0]);
var assembly3 = domain.Load(AssemblyName.GetAssemblyName("c:\\Changed-assemply-info-and-recompile-SampleCodedFormula.dll"));
Console.WriteLine(assembly3.CodeBase);
Console.WriteLine(assembly3.GetExportedTypes()[0]);
I wrote some sample code like this, all the outputs are the same, which is weird for me,
I guess it makes sense if assembly1 is as same as assemly2, since the assembly information is the same(such as name, assembly version, GUID and etc.)
however, I changed the assembly information and recompile the SampleCodedFormula.dll(then rename it to Changed-assemply-info-and-recompile-SampleCodedFormula.dll), surprisingly, the assembly3 output is still same as assembly1.
assembly1,2,3 are compiled from the same codebase.
Can anyone tell me why the behavior is like this? does it make sense to you?
var domain = AppDomain.CurrentDomain;
var assembly1 = domain.Load(AssemblyName.GetAssemblyName("c:\\SampleCodedFormula.dll"));
Console.WriteLine(assembly1.CodeBase);
Console.WriteLine(assembly1.GetExportedTypes()[0]);
var assembly2 = domain.Load(AssemblyName.GetAssemblyName("c:\\Copied-From-SampleCodedFormula.dll"));
Console.WriteLine(assembly2.CodeBase);
Console.WriteLine(assembly2.GetExportedTypes()[0]);
var assembly3 = domain.Load(AssemblyName.GetAssemblyName("c:\\Changed-assemply-info-and-recompile-SampleCodedFormula.dll"));
Console.WriteLine(assembly3.CodeBase);
Console.WriteLine(assembly3.GetExportedTypes()[0]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需像这样检查程序集的版本
或
使用 FileVersionInfo 对象即可。以下是 Microsoft 网站上的示例,该示例从 notepad.exe 获取版本信息
Just by checking verstion of assembly like this
or
Use the FileVersionInfo object. Here's an example from the Microsoft website that gets the version info from notepad.exe