在C#控制台应用程序中显示主要/次要版本的最佳方法是什么?

System.Windows.Forms命名空间包含一个ProductVersion类,可用于显示通过Visual Studio项目属性(程序集信息)设置的名称/版本信息。因此,这是我目前的机制:

  

Console.WriteLine(" {0}({1})",System.Windows.Forms.Application.ProductName,System.Windows.Forms.Application.ProductVersion);

为什么这部分表格?这适用于控制台应用程序吗?

有帮助吗?

解决方案

Assembly.GetExecutingAssembly().GetName().Version

此外,您仍然可以使用该类,您只需要引用包含的程序集。这不是什么大事。

其他提示

Assembly.GetExecutingAssembly()。GetName()。版本 Application.ProductVersion 不同(但根据您的环境可能还不错。

从Lutz Reflector可以看出, Application.ProductVersion 首先尝试使用 Assembly.GetEntryAssembly()中的 AssemblyInformationalVersion 属性,如果它是present,如果 GetEntryAssembly()不为null。

否则它使用可执行文件的文件版本。

我认为没有理由不在控制台应用程序中使用 Application.ProductVersion

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top