c# – Get Product Version and Assembly Version of external application

By | 7. December 2016

Sometimes it is needed to know version of external application’s  Product Version or Assembly Version.

It is actually very easy task.

using System;
using System.Diagnostics;
using System.Reflection;

namespace GetAppVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("Please enter program path.");
                return;
            }

            try
            {
                var versionInfo = FileVersionInfo.GetVersionInfo(args[0]);
                Console.WriteLine($"ProductVersion: {versionInfo.ProductVersion}");
                Console.WriteLine($"FileVersion: {versionInfo.FileVersion}");

            }
            catch (Exception)
            {

                // throw;
            }

            try
            {
                string assemblyVersion = AssemblyName.GetAssemblyName(args[0]).Version.ToString();
                Console.WriteLine($"AssemblyVersion: {assemblyVersion}");
            }
            catch (Exception)
            {
                //throw;
            }
            

        }
    }
}

As not version information parts might not be present the try-catch is a must. On other hand there is nothing to do if error occurs, so it is just ignored.

Now we set version info for our product for later testing :

productversion1

Now is time to test what we got:

productversion2

Some more samples – notepad.exe

productversion3

Also working with dll-s : Microsoft.VisualStudio.Shell.Interop.9.0.dll

productversion4

Mission completed.

Leave a Reply