大型程序的一个小功能是检查文件夹中的程序集并用最新版本替换过时的程序集。为此,它需要读取现有程序集文件的版本号,而无需将这些程序集实际加载到执行进程中。
最佳答案
我找到了以下 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/