"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to get AssemblyVersion and AssemblyFileVersion in .NET?

How to get AssemblyVersion and AssemblyFileVersion in .NET?

Posted on 2025-04-16
Browse:524

How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3