Solved

Visual Basic .NET 2013:  Version/Build Number Variable

Posted on 2014-09-08
6
1,316 Views
Last Modified: 2014-09-11
I have been attempting to determine if there is a variable or object that can access that will provide the Version/Build number of my application.  I have a command line application that generates a log file, and I would like to include this information there (so that I can be sure that the application being executed is the latest and greatest).

Thanks in Advance!

- Michael
0
Comment
Question by:mjs082969
  • 2
  • 2
  • 2
6 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40310598
You can use Application.ProductVersion
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40310609
Actually that returns whats in the config. So use this instead:
        Dim strMajorVersion, strMinorVersion, strBuildVersion, strRevisionVersion As String

        strMajorVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major()
        strMinorVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor()
        strBuildVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build()
        strRevisionVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision()

        MsgBox("Version - " & strMajorVersion & "." & strMinorVersion & "." & strBuildVersion & "." & strRevisionVersion)

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40310681
VB makes this a bit easier than C# does by way of the My namespace:

Dim majorVersion As Integer = My.Application.Info.Version.Major
Dim minorVersion As Integer = My.Application.Info.Version.Minor
Dim buildNumber As Integer = My.Application.Info.Version.Build
Dim majorRevision As Integer = My.Application.Info.Version.MajorRevision
Dim minorRevision As Integer = My.Application.Info.Version.MinorRevision

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 40
ID: 40311203
Randy, your first answer was OK.

The ProductVersion is not saved in the .config file. It is saved in the AssemblyInfo.vb file, that is usually not visible, but created from the information typed under Assembly Information, in the Application tab of the project's Properties window. When you compile the application, that information is recorded in the assemblies manifest. The .config file does not hold anything about the version, unless you use a custom version mechanism and record it in the Settings of the application or directly in the .config file.

You do not need to go through Reflection, or use My.Application. That are indirect routes to that information (sorry kaufmed, but My is simply a VB shortcut to framework classes, and it hides a lot of useful stuff). No need either to go through the Major, Minor and build properties to get the information unless you need to isolate the different parts.

The way I understand it, msj082969 simply wants to record the version number, and Application.ProductName returns a String, already in the right format for display or recording, that contains all these values in one call.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40311223
@JamesBurger

Randy, your first answer was OK.
Provided this is a Forms app, which according to the OP it is not. The Application class is not available in console applications or libraries--at least, not without importing some of the namespaces within System.Windows.Forms.

...but My is simply a VB shortcut to framework classes...
I'm well aware of that  = )

The way I understand it, msj082969 simply wants to record the version number, and Application.ProductName returns a String, already in the right format for display or recording, that contains all these values in one call.
So call ToString on the Version property.

e.g.

Console.WriteLine(My.Application.Info.Version.ToString())

Open in new window


@mjs082969

You'll probably want to make sure that you make the distinction between "Assembly version" and "File version". The former is more akin to a product version, and it is what .NET will use when determining references to use; the latter is what is displayed in Windows Explorer. With the former, you run the risk of invalidating users' references to your libraries.
0
 
LVL 40
ID: 40311258
@kaufmed

You got me on that one. I did not read "command line application" as console, because most of my applications are Windows Applications that can be launched with parameters through a "command line". Such is the pain of speaking French. You miss these little nuances in your second language sometimes. You are probably right that this is a question about a console application.

As for the use of My, I always tell my students to skip that one, except for My.Settings and My.Resources. My might make things easier at first, but it hides too many good things to really be useful for serious development. I would rather lead any programmer to the "real" framework classes than telling them about My.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now