开发者

How does .NET know the dll is the same?

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.)

howeve开发者_运维知识库r, 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]);


Just by checking verstion of assembly like this

 // get the version object for this assembly
        Version v = System.Reflection.Assembly.GetExecutingAssembly().
         GetName().Version;

or

Use the FileVersionInfo object. Here's an example from the Microsoft website that gets the version info from notepad.exe

public void GetFileVersion() {
    // Get the file version for the notepad.
    FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\\Notepad.exe");

    // Print the file name and version number.
    textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' +
       "Version number: " + myFileVersionInfo.FileVersion;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜