如何在我的日志中打印正在运行的程序的版本?换句话说,我可以使用Console.WriteLine访问AssemblyFileVersion吗?
谢谢托尼
看起来像这样的东西会起作用:
public static string Version
{
get
{
Assembly asm = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart);
}
}
Run Code Online (Sandbox Code Playgroud)
来自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());
Run Code Online (Sandbox Code Playgroud)
更多关于 MSDN: