Retrieving Assembly File Version from AssemblyInfo
The AssemblyInfo file defines two assembly versions: AssemblyVersion and AssemblyFileVersion. While AssemblyVersion specifies the attributed assembly version, AssemblyFileVersion instructs the compiler to use a particular version number for the Win32 file version resource, which may differ from the AssemblyVersion.
To retrieve the AssemblyVersion, you can use the code snippet:
Version version = Assembly.GetEntryAssembly().GetName().Version;
However, obtaining the AssemblyFileVersion requires a different approach. Here's how you can get it:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion;
This code fetches the active assembly, retrieves its file version information, and extracts the file version.
The above is the detailed content of How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?. For more information, please follow other related articles on the PHP Chinese website!