c# – Get Product Version and Assembly Version of external application
Sometimes it is needed to know version of external application’s Product Version or Assembly Version. It is actually very easy task.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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… Read More »