Home >Backend Development >C++ >How to Retrieve AssemblyVersion and AssemblyFileVersion in C#?
Retrieving Assembly File Version in C#
In .NET assemblies, two distinct version numbers coexist: AssemblyVersion and AssemblyFileVersion. While AssemblyVersion specifies the version of the assembly, AssemblyFileVersion is used by a compiler to determine the file version for Win32 resource purposes. This file version doesn't necessarily align with the assembly's version.
Getting AssemblyVersion
Retrieving the AssemblyVersion is straightforward. Using reflection, you can access it with the code:
Version version = Assembly.GetEntryAssembly().GetName().Version;
Obtaining AssemblyFileVersion
However, getting the AssemblyFileVersion requires an additional step. Here's how you can do it:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); string fileVersion = fvi.FileVersion;
This code obtains the assembly from the executing application, extracts its file path, and uses the FileVersionInfo class to retrieve the file version as a string. The example also assumes that the file version resource is set in the assembly manifest.
The above is the detailed content of How to Retrieve AssemblyVersion and AssemblyFileVersion in C#?. For more information, please follow other related articles on the PHP Chinese website!