7

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.

Milo Kofax
  • 73
  • 1
  • 1
  • 4
  • Duplicate: http://stackoverflow.com/questions/1248824/how-do-i-get-the-current-published-version-in-a-net-application – Max May 07 '13 at 17:28

5 Answers5

12

This should get you the publish version:

ApplicationDeployment.CurrentDeployment.CurrentVersion
GJKH
  • 1,715
  • 13
  • 30
  • 1
    For reference: [the msdn link](http://msdn.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.currentversion.aspx) – gunr2171 May 07 '13 at 16:23
  • 4
    you need to include System.Deployment.Application – greg Jul 11 '13 at 16:24
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.

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.

Hille
  • 2,123
  • 22
  • 39
2

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
RBLevin
  • 51
  • 6
1

Try this one:

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

The publish version will appear in runtime.

trevorp
  • 1,161
  • 1
  • 14
  • 19
Mel
  • 11
  • 1
1

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
Isidoros Moulas
  • 520
  • 3
  • 10