Home >Backend Development >C++ >How to Retrieve AssemblyFileVersion in C#?

How to Retrieve AssemblyFileVersion in C#?

Linda Hamilton
Linda HamiltonOriginal
2024-12-27 08:08:17298browse

How to Retrieve AssemblyFileVersion in C#?

Retrieving Assembly File Version

In AssemblyInfo, two distinct versions are defined:

  • AssemblyVersion: Represents the version of the attributed assembly.
  • AssemblyFileVersion: Specifies the version number used by a compiler for the Win32 file version resource. This number may differ from the assembly version.

While you can obtain the AssemblyVersion using Assembly.GetEntryAssembly().GetName().Version, the AssemblyFileVersion requires a different approach:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;

This code retrieves the assembly from the current executable, extracts the FileVersionInfo using its location, and ultimately extracts the FileVersion.

The above is the detailed content of How to Retrieve AssemblyFileVersion in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn