App.Revision
Although App.Revision isn t actually a project item, the VB Application Wizard projects use it in several places, so we ll discuss it right at the beginning. In Visual Basic 6, it is common to concatenate the three App object properties App.Major, App.Minor, and App.Revision together to create a version number for the application. For example, in frmAbout, you will find the following line of code in Form_Load:
lblVersion.Caption = "Version " & App.Major & "." & App.Minor & _ "." & App.Revision
Visual Basic .NET does not have an App object, so the Upgrade Wizard chooses the most appropriate upgrade for each property. App.Major is upgraded to
System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMajorPart
App.Minor is upgraded to
System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMinorPart
However, there is no equivalent for App.Revision, so the Upgrade Wizard leaves it asis, which creates a compile error in Visual Basic .NET. For example, the Visual Basic 6 line
lblVersion.Caption = "Version " & App.Major & "." & App.Minor & _ "." & App.Revision
upgrades to
lblVersion.Text = "Version " & _ System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMajorPart _ & "." & System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMinorPart & "." & App.Revision
There are two ways to fix the compile error. The first and easiest is simply to remove the App.Revision part of the line:
& "." & App.Revision
After this change, only the major and minor parts of the version will be shown. Here is what the code just shown looks like after the App.Revision part is removed:
lblVersion.Text = "Version " & System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMajorPart _ & "." & System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMinorPart
While this is a good option, Visual Basic .NET also has a property that returns the entire version number of the application in 0.0.0.0 format. This property is the best way to create a version number in Visual Basic .NET, since it gives the full version information. Here is the replacement code:
lblVersion.Text = "Version " & Application.ProductVersion
You ll also notice that this line is shorter than the Visual Basic 6 version. You can use this line as a replacement for any code that concatenates together App.Major, App.Minor, and App.Revision to generate a version number.
What s Up with Versioning in Visual Basic .NET?
Visual Basic 6 has three versioning properties: App.Major, App.Minor, and App.Revision. You can choose to make App.Revision auto-increment so that the revision number increases each time you compile the project. Although this is a simple model, it is out of step with Windows versioning, which supports four versioning properties: Major, Minor, Revision, and Build. When a Visual Basic 6 project is compiled, App.Revision is mapped to the Windows Build property and the Windows Revision property is left blank. Visual Basic .NET supports the four Windows versioning properties. The version number is set using the AssemblyVersion attribute in the AssemblyInfo.vb file. By default, the revision and build are set to be auto-incrementing based on the time of compilation when combined they are a timestamp giving the date and time of compilation.