Solved

Visual Basic .NET 2013:  Version/Build Number Variable

Posted on 2014-09-08
6
1,528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I change a label on default.aspx from my public class, class1.vb? 11 27
Data Analysis 7 59
Select coumns form Data table? 3 27
Convert a string to date 4 40
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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