How can I print in my log the version of the program that is running? In other words, can I access AssemblyFileVersion using Console.WriteLine?
Thanks Tony
It looks like something like this would work:
public static string Version
{
get
{
Assembly asm = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart);
}
}
From another post on SO.
// Get the version of the current application.
Assembly assem = Assembly.GetExecutingAssembly();
AssemblyName assemName = assem.GetName();
Version ver = assemName.Version;
Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString());
More on MSDN:
FileVersionInfo.GetVersionInfo(asm.Location) doesn't work for embedded assemblies (e.g. using Fody's Costura to ship a single EXE instead of the executable and all of it's dependent assemblies). In which case, the following works as a fallback:
var assembly = Assembly.GetExecutingAssembly();
var fileVersionAttribute = assembly.CustomAttributes.FirstOrDefault(ca => ca.AttributeType == typeof(AssemblyFileVersionAttribute));
if (fileVersionAttribute != null && fileVersionAttribute.ConstructorArguments.Any())
return fileVersionAttribute.ConstructorArguments[0].ToString().Replace("\"","");
return string.Empty;