Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'd simply like to print out the revision number on the main form, so the users could have a way of seeing what version (revision) they are running.

It auto-increments the revision number for me in VS2008, but I can't figure out how to access that same number at runtime.

I've tried...

Dim xversion As String
xversion = My.Application.Info.Version.ToString

and

xversion = System.Windows.Forms.Application.ProductVersion.ToString


and a few other examples I've read online. Seems like this would be easy to grab.

I've also tried setting the AssemblyInfo.vb file code to read

<assembly: xmlns:assembly="#unknown"></assembly:>


Still no luck. This is on a windows forms application... any advice/reply would be appreciated.
Posted
Updated 12-May-11 22:12pm
v3
Comments
Dalek Dave 13-May-11 4:12am    
Edited for Grammar and Readability.

Why not using really universal method?

System.Reflection.Assembly.GetEntryAssembly().GetName().Version

' or:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version

' or any other assembly


—SA
 
Share this answer
 
Comments
Dalek Dave 13-May-11 4:13am    
Sensible.
Sergey Alexandrovich Kryukov 13-May-11 4:53am    
Thank you, Dalek.
--SA
We can also try
VB
Public Class Class1
    Dim currentAppVersion = My.Application.Deployment.CurrentVersion
    Dim lastUpdateDate = My.Application.Deployment.TimeOfLastUpdateCheck
End Class


to retrive the version, if the deployment model is 'Click Once'
 
Share this answer
 
Comments
Dalek Dave 13-May-11 4:13am    
Nice.
Sergey Alexandrovich Kryukov 13-May-11 4:54am    
This is an extra thing, but good to know, too. My 5.
--SA
The My.Application.Info.Version is an object of type <a href="http://msdn.microsoft.com/en-us/library/system.version.aspx">System.Version</a>[<a href="http://msdn.microsoft.com/en-us/library/system.version.aspx" target="_blank" title="New Window">^</a>].

You can get all the version information from that object properties including revision.
 
Share this answer
 
Comments
tencentguitar 10-May-11 17:42pm    
can you give me an example of retrieving the revision number in code, into a string?
I have tried using My.Application.Info.Version and My.Application.Info.Version.Revision

The .Version isn't the same revision number as i'm working with when i set it in the project/properties/publish/publish version/revision area (that auto increments). I am expecting (wanting) a .99 and it prints something like .28123

...using code such as this produces that .28123 number:
Dim assem As Assembly = Assembly.GetEntryAssembly()
Dim assemName As AssemblyName = assem.GetName()
Dim ver As Version = assemName.Version
Console.WriteLine("Application {0}, Version {1}", assemName.Name, ver.ToString())
Fabio V Silva 10-May-11 17:46pm    
If you are publishing with clickonce you need to use the My.Application.Deployment.CurrentVersion.Revision.

The publish version is not synchronized with the assembly version.
tencentguitar 10-May-11 18:08pm    
thank you. that seemed to be it!
Dalek Dave 13-May-11 4:13am    
Good Answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900