Winforms: getting Publish Version number?

百般思念 提交于 2020-12-02 12:47:15

问题


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)?

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

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


回答1:


This should get you the publish version:

ApplicationDeployment.CurrentDeployment.CurrentVersion



回答2:


Try this one:

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

The publish version will appear in runtime.

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.




回答3:


Try this one:

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

The publish version will appear in runtime.




回答4:


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



回答5:


That worked for me Isidoros, with the following ToString modification.

Imports System.Deployment.Application

If ApplicationDeployment.IsNetworkDeployed Then
    strTemp = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString
Else
    strTemp = Application.ProductVersion.ToString
End If


来源:https://stackoverflow.com/questions/16423729/winforms-getting-publish-version-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!