Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net NET如何知道dll是相同的?_.net_Assemblies_Appdomain - Fatal编程技术网

.net NET如何知道dll是相同的?

.net NET如何知道dll是相同的?,.net,assemblies,appdomain,.net,Assemblies,Appdomain,我写了一些这样的示例代码,所有的输出都是一样的,这对我来说很奇怪 我想如果assembly2和assembly1一样,这是有意义的,因为程序集信息是相同的(例如名称、程序集版本、GUID等) 但是,我更改了程序集信息并重新编译了SampleCodedFormula.dll(然后将其重命名为changed assemply info并重新编译SampleCodedFormula.dll),令人惊讶的是,assembly3输出仍然与assembly1相同 assembly1、2、3是从同一个代码库编

我写了一些这样的示例代码,所有的输出都是一样的,这对我来说很奇怪

我想如果assembly2和assembly1一样,这是有意义的,因为程序集信息是相同的(例如名称、程序集版本、GUID等)

但是,我更改了程序集信息并重新编译了SampleCodedFormula.dll(然后将其重命名为changed assemply info并重新编译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]);

只需像这样检查组件的版本

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

使用FileVersionInfo对象。下面是一个来自Microsoft网站的示例,它从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;
 }