How do I get the version of an assembly without loading it?
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);
Depending on the files, one option might be FileVersionInfo
- i.e.
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path)
string ver = fvi.FileVersion;
The problem is that this depends on the code having the [AssemblyFileVersion]
attribute, and it matching the [AssemblyVersion]
attribute.
I think I'd look at the AssemblyName options suggested by others first, though.