C # how to print AssemblyFileVersion

How can I print the version of the program that is running in my journal? In other words, can I access AssemblyFileVersion using Console.WriteLine?

Thank you, Tony

+4
source share
3 answers

It seems like something like this will 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 message in SO format .

+5
source
 // 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 about MSDN:

Version class

+2
source

FileVersionInfo.GetVersionInfo (asm.Location) does not work for built-in assemblies (for example, using Fody Costura to send a single EXE instead of an executable file and all its dependent assemblies). In this case, the following works as a reserve:

 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; 
0
source

All Articles