Solved

Visual Basic .NET 2013:  Version/Build Number Variable

Posted on 2014-09-08
6
1,247 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 74

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 74

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

16 Experts available now in Live!

Get 1:1 Help Now