Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the assembly file version

In AssemblyInfo there are two assembly versions:

  1. AssemblyVersion: Specify the version of the assembly being attributed.
  2. AssemblyFileVersion: Instructs a compiler to use a specific version number for the Win32 file version resource. The Win32 file version is not required to be the same as the assembly's version number.

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

Version version = Assembly.GetEntryAssembly().GetName().Version; 

But how can I get the Assembly File Version?

like image 587
Enyra Avatar asked May 26 '09 08:05

Enyra


People also ask

Where is 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.

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.

What is an assembly version?

The Product version of the assembly. This is the version you would use when talking to customers or for display on your website. This version can be a string, like '1.0 Release Candidate'. The AssemblyInformationalVersion is optional. If not given, the AssemblyFileVersion is used.

What is the order of an assembly version?

The AssemblyVersion attribute assigns the version number of the assembly, and this is embedded in the manifest. Version information for an assembly consists of the following four values : a major and minor version number, and two further optional build and revision numbers.


2 Answers

See my comment above asking for clarification on what you really want. Hopefully this is it:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; 
like image 94
Xiaofu Avatar answered Oct 08 '22 03:10

Xiaofu


There are three versions: assembly, file, and product. They are used by different features and take on different default values if you don't explicit specify them.

string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();  string assemblyVersion = Assembly.LoadFile("your assembly file").GetName().Version.ToString();  string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;  string productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; 
like image 40
Check6 Avatar answered Oct 08 '22 04:10

Check6