vb.net Application.ProductVersion 总是返回 1.0.0.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4014687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:06:08  来源:igfitidea点击:

Application.ProductVersion always returns 1.0.0.0

vb.net

提问by Tom

On the publish tab of My Project the correct current version is there, 1.1.0.0 and in Programs and Features under Control Panel it shows 1.1.0.0 but when I reference Application.ProductVersion I get 1.0.0.0.

在我的项目的发布选项卡上,正确的当前版本是 1.1.0.0,在控制面板下的程序和功能中,它显示 1.1.0.0,但是当我引用 Application.ProductVersion 时,我得到 1.0.0.0。

What am I doing wrong or what am I missing here?

我做错了什么或者我在这里错过了什么?

Thanks.

谢谢。

回答by DJIDave

The assemby version (in the application.config file) and the ClickOnce Publish version are 2 seperate numbers.

程序集版本(在 application.config 文件中)和 ClickOnce Publish 版本是 2 个单独的数字。

If you want to get the ClickOnce version at runtime you can use the following code

如果要在运行时获取 ClickOnce 版本,可以使用以下代码

     If (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) Then
        With System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion
            Me.Text = "V" & .Major & "." & .Minor & "." & .Build
        End With
     End If

Edit:For the full, four-segment revision number you'll need:

编辑:对于完整的四段修订号,您需要:

Me.Text = "V" & .Major & "." & .Minor & "." & .Build & "." & .Revision 

回答by Our Man in Bananas

With System.Reflectionyou can use:

有了System.Reflection你可以使用:

Dim versionNumber As Version

versionNumber = Assembly.GetExecutingAssembly().GetName().Version

and then call .ToString()on that if needed...

然后.ToString()在需要时调用它...

and yet another method is to call

还有一种方法是调用

System.Windows.Forms.Application.ProductVersion

(for Full DisclosureI found this on MSDN Forums)

(为了完全披露,我在MSDN 论坛上找到了这个)

回答by cardmagik

I know this is old, but in Visual Studio Express 2013, I ran across the same issue. I wanted to use variable ProductVersion like so:

我知道这是旧的,但在 Visual Studio Express 2013 中,我遇到了同样的问题。我想像这样使用变量 ProductVersion :

msgbox (Application.ProductVersion)

but it always returned 1.0.0.0 no matter what I put in the settings for Publish. I found instead I had to put it in Application > Assembly > File Version (I updated both Assembly version and File Version, but it's the File Version that counts).

但无论我在发布设置中放什么,它总是返回 1.0.0.0。我发现我不得不把它放在应用程序>程序集>文件版本中(我更新了程序集版本和文件版本,但重要的是文件版本)。

Application >Assembly >File Version

应用程序 >组装 >文件版本

You get to this using Project > Properties:

您可以使用“项目”>“属性”来实现:

Project Properties

项目属性

Now, I only wanted the major and minor numbers (to concatenate to the form title) so I used this:

现在,我只想要主要和次要数字(连接到表单标题),所以我使用了这个:

MsgBox(Application.ProductVersion.Substring(0, 3))

Hope this helps others. It was a lot of digging!

希望这对其他人有帮助。这是很多挖掘!

回答by MichaelMocko

Maybe you should try to explicitly put an attribute on your assembly: for example: [assembly: AssemblyVersion("1.1.0.0")]

也许您应该尝试在程序集上显式放置一个属性:例如:[assembly: AssemblyVersion("1.1.0.0")]

Regards, Michael.

问候,迈克尔。