如何获取exe文件的版本C# [英] How to get the version of an exe file C#

查看:388
本文介绍了如何获取exe文件的版本C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从安装的exe文件中获取文件版本并将其显示在标签中?

  var  versionInfo = FileVersionInfo.GetVersionInfo( @  C:\ Users \ Me \Downloads\vlc.exe ); 
string version = versionInfo.ProductVersion;
LBL_Version.Text =版本;





我的尝试:



我试过这样做,但它没有给我看任何东西。

下面的代码就是我试过的。

解决方案

< blockquote>请参阅 FileVersionInfo.GetVersionInfo Method(String)( System.Diagnostics) [ ^ ]:



  • 如果文件不存在,则抛出异常。
  • 将始终只设置 VersionInfo FileName 属性。其他属性仅在存在时设置。


如果未收到异常且未显示任何内容,则该文件可能不包含特定版本信息(产品版本 这里)。然后,您可以尝试读取文件版本属性,该属性通常在两者都存在时包含相同的版本。



只需使用Windows资源管理器,右键单击文件,选择属性,然后选择详细信息选项卡以查看存在哪些属性。

您可以使用调试器检查存在的值,并在捕获版本信息的语句之后停止。您还可以使用 ToString 方法获取部分详细信息,如 FileVersionInfo.ToString Method(System.Diagnostics) [ ^ ]。


How can I get file versions from exe files installed and show them in a label?

var versionInfo = FileVersionInfo.GetVersionInfo(@"C:\Users\Me\Downloads\vlc.exe");
              string version = versionInfo.ProductVersion;
              LBL_Version.Text = version;



What I have tried:

I tried to do it but it doen't show me anything.
The code below is what I tried.

解决方案

See FileVersionInfo.GetVersionInfo Method (String) (System.Diagnostics)[^]:

  • If the file does not exist, an exception is thrown.
  • Only the FileName property of the VersionInfo will be always set. Other properties are only set when present.

If you did not get an exception and nothing is shown, the file probably does not contain the specific version information ("Product Version" here). You can then try to read the "File Version" property which usually contains the same version when both are present.

Just use the Windows Explorer by right clicking on the file, choosing properties, and selecting the Details tab to see which properties are present.


You can check what values exist by using the debugger and stopping after the statement that captures the version information. You can also use the ToString method to get partial details as described at FileVersionInfo.ToString Method (System.Diagnostics)[^].


这篇关于如何获取exe文件的版本C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆