C# Tips and Tricks #20 – Get Assembly File Version

When you check the Project properties your .NET Application , you would notice the following properties.

  • AssemblyVersion
  • AssemblyFileVersion
SNAGHTML1fee7fe0

Its pretty easy to get the Assembly Version of the project using the Version property as shown below.

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

but , how do one get the assembly file version number ?.

How to get the Assembly File Version in C# ?

When you right click on the assembly , you would be able to see the Assembly File version as shown below.

SNAGHTML1fef72f5

To get this property , you can use reflection and retreive it as shown below.

public static string GetAssemblyFileVersion()
{
             System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
             FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
             return fileVersion.FileVersion;
 }
image

Full code snippet that is used for this demo is shown below.

using System;
using System.Diagnostics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string version = GetAssemblyFileVersion();
            Console.WriteLine(version);
            Console.ReadLine();
        }

        public static string GetAssemblyFileVersion()
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
            return fileVersion.FileVersion;
        }
    }
}
    
Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *