Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 version numbers of the existing assembly files without actually loading those assemblies into the executing process.

like image 336
Jay Cincotta Avatar asked Oct 09 '08 16:10

Jay Cincotta


People also ask

How do I know my assembly version?

If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.

Where is the version information stored of an assembly?

The version number is stored in the assembly manifest along with other identity information, including the assembly name and public key, as well as information on relationships and identities of other assemblies connected with the application.

How can you get the assembly version in C#?

I can get the Assembly Version with the following line of code: Version version = Assembly.

What is assembly version and file version?

It's the version number given to file as in file system. It's displayed by Windows Explorer, and never used by . NET framework or runtime for referencing.


1 Answers

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); 
like image 58
Joel B Fant Avatar answered Sep 30 '22 23:09

Joel B Fant