我可以在vb6中使用App.Major
、App.Minor
、App.Revision
等获取exe的文件版本(它自己的版本),但是如何在vb.net中获得相同的文件版本。我尝试使用以下3种方法。
Text1.Text = My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision
Text2.Text = Me.GetType.Assembly.GetName.Version.ToString()
Text3.Text = My.Application.Info.Version.ToString()
在所有3种情况下,它都返回了程序集版本(我在bin文件夹中检查了它,其中xp machine.In windows 8中创建的exe没有看到任何选项,比如当我看到文件属性时没有看到任何类似组装版本的选项)。
默认情况下,程序集和文件版本都是same.But,当我在project properties->applicationassembly information->File version
中手动更改它时,我才知道我的代码正在返回程序集版本。那么我怎样才能得到文件版本呢?什么是汇编和文件?
发布于 2013-04-05 07:58:14
例如,使用FileVersionInfo.GetVersionInfo
:
Dim myFileVersionInfo As FileVersionInfo =
FileVersionInfo.GetVersionInfo([Assembly].GetExecutingAssembly().Location)
发布于 2013-11-26 20:04:33
因此,在.NET程序中,实际上有两个版本,而不仅仅是一个版本(我知道)。程序集版本是您要获取的内容,在.NET中检索起来更容易。它本质上是“.NET的版本”,所以当程序集有不同的版本时,它就会使用它。
然后是“文件版本”,或者在我看到的一个地方,微软甚至称它为“汇编文件版本”,以使混乱更加严重。因此,我们确实需要查看名称是否包括"file“。程序集的" file“版本与文件系统相关联,所以当您查看Windows中的版本时,您将得到以下内容。
为什么微软把它们分割成两种不同的东西而不把它们绑在一起,我不明白。也许有人能进一步启发我。
我刚想出了抓取FileVersion的代码。我发现这个问题是因为我也在寻找如何检索它(在VB中,而不是在C#中)。我认为C#使大多数事情变得更容易,包括访问程序集。下面是用于检索程序的文件版本的VB代码:
Dim fileName$ = System.Reflection.Assembly.GetExecutingAssembly().Location
Dim fileName2$ = Application.ExecutablePath ' this grabs the filename too,
' but #2 ends with ".EXE" while the 1st ends with ".exe" in my Windows 7.
' either fileName or fileName2 works for me.
Dim fvi As FileVersionInfo = FileVersionInfo.GetVersionInfo(fileName)
' now this fvi has all the properties for the FileVersion information.
Dim fvAsString$ = fvi.FileVersion ' but other useful properties exist too.
哇,应该像在VB6中那样简单的东西的代码很多。甚至可能是App.Version.ToString之类的。哇。干得好,微软!至少这个不像他们的一些特技那么难,就像只演奏自己的弦乐。
发布于 2014-09-28 01:48:32
实际上,接受Shawns的回答并对其进行一些改进,您可以使用一行代码检索文件版本。
Dim FileVer As String = FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileVersion
或者你可以把它放在标签里
Me.Label1.Text = FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileVersion
干得真好!VB.NET和往常一样简单..。
https://stackoverflow.com/questions/15828509
复制相似问题