How do I get the version of an assembly without loading it?

后端 未结 4 873
故里飘歌
故里飘歌 2020-12-01 17:53

One small function of a large program examines assemblies in a folder and replaces out-of-date assemblies with the latest versions. To accomplish this, it needs to read the

4条回答
  •  醉梦人生
    2020-12-01 18:47

    I found the following in this article.

    using System.Reflection;
    using System.IO;
    
    ...
    
    // Get current and updated assemblies
    AssemblyName currentAssemblyName = AssemblyName.GetAssemblyName(currentAssemblyPath);
    AssemblyName updatedAssemblyName = AssemblyName.GetAssemblyName(updatedAssemblyPath);
    
    // Compare both versions
    if (updatedAssemblyName.Version.CompareTo(currentAssemblyName.Version) <= 0)
    {
        // There's nothing to update
        return;
    }
    
    // Update older version
    File.Copy(updatedAssemblyPath, currentAssemblyPath, true);
    

提交回复
热议问题