vb.net Winforms:获取发布版本号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16423729/
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-17 13:31:24  来源:igfitidea点击:

Winforms: getting Publish Version number?

vb.netwinformssystem.reflection

提问by Milo Kofax

I've got a Winforms app and want to display the version number so that we can know if our update scripts are running correctly. Is there a way to get the Publish Version number (as displayed in the Property Pages of the app, Publish tab)?

我有一个 Winforms 应用程序,想显示版本号,以便我们知道我们的更新脚本是否正确运行。有没有办法获取发布版本号(如应用程序的属性页中的“发布”选项卡中所示)?

When I use Reflection.Assembly.GetExecutingAssembly().GetName().Version etc it seems to use the AssemblyVersion number from AssemblyInfo.vb, which isn't the same.

当我使用 Reflection.Assembly.GetExecutingAssembly().GetName().Version 等时,它似乎使用了 AssemblyInfo.vb 中的 AssemblyVersion 编号,这并不相同。

If I use wildcards in the AssemblyInfo.vb it comes out different numbers again.

如果我在 AssemblyInfo.vb 中使用通配符,它​​会再次出现不同的数字。

回答by GJKH

This should get you the publish version:

这应该为您提供发布版本:

ApplicationDeployment.CurrentDeployment.CurrentVersion

回答by beetle442002

Try this one:

If My.Application.IsNetworkDeployed Then
     Label1.Text = My.Application.Deployment.CurrentVersion.ToString()
End If

The publish version will appear in runtime.

试试这个:

If My.Application.IsNetworkDeployed Then
     Label1.Text = My.Application.Deployment.CurrentVersion.ToString()
End If

发布版本将出现在运行时。

I didn't catch the "publish version will appear in runtime" to start with but I was able to use this and set my label to say "N/A during debug " then when published it changes and displays the published version.

我没有注意到“发布版本将出现在运行时”一开始,但我能够使用它并将我的标签设置为“调试期间不适用”,然后在发布时它会更改并显示已发布的版本。

回答by Mel

Try this one:

试试这个:

If  My.Application.IsNetworkDeployed Then
    Label1.Text = My.Application.Deployment.CurrentVersion.ToString()
End If

The publish version will appear in runtime.

发布版本将出现在运行时。

回答by Isidoros Moulas

If application is not published you will get an error or you are in development mode you will get an error. Try the below:

如果应用程序未发布,您将收到错误消息,或者您处于开发模式,您将收到错误消息。试试下面的:

Imports System.Deployment.Application

If ApplicationDeployment.IsNetworkDeployed Then
   lblVersion.Text = ApplicationDeployment.CurrentDeployment.CurrentVersion
Else
   lblVersion.Text = Application.ProductVersion
End If