Jay*_*tta 24 .net assemblies versions
大型程序的一个小功能检查文件夹中的程序集,并用最新版本替换过时的程序集.要实现此目的,它需要读取现有程序集文件的版本号,而不实际将这些程序集加载到执行过程中.
Joe*_*ant 36
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);
Run Code Online (Sandbox Code Playgroud)
Mar*_*ell 12
根据文件,一个选项可能是FileVersionInfo- 即
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path)
string ver = fvi.FileVersion;
Run Code Online (Sandbox Code Playgroud)
问题是这取决于具有[AssemblyFileVersion]属性的代码,并且它与[AssemblyVersion]属性匹配.
我想我会首先看一下其他人建议的AssemblyName选项.