.net - 如何在不加载程序集的情况下获取程序集的版本?

标签 .net assemblies versions

大型程序的一个小功能是检查文件夹中的程序集并用最新版本替换过时的程序集。为此,它需要读取现有程序集文件的版本号,而无需将这些程序集实际加载到执行进程中。

最佳答案

我找到了以下 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);

关于.net - 如何在不加载程序集的情况下获取程序集的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187999/

相关文章:

crystal-reports - 混合模式程序集是针对版本X构建的,如果没有其他配置信息,则无法在运行时的版本Y中加载

.net - 多文件程序集

.NET:强命名与 Authenticode

xcode - Opendiff 不再启动

c# - 如何识别活跃的子窗体并触发通用方法(每个子窗体中都存在)?

.net - 从字符串 "-1"到类型 'Integer' 的转换无效,但字符串值是有效的 int

c# - 从 ADUser 获取 UserPrincipal

.Net:最先进的工具和框架

svn - 设置 SVN 存储库的基础知识