BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Programming
.NET 1.1+

Windows Forms Application Version Numbers

Using the information in the AssemblyInfo class file, various information relating to a Windows Forms application can be defined, including a four-part version number. This information can be particularly helpful when multiple versions are in live usage.

Version Numbers

All .NET assemblies include a version number that is arranged into four sections. Each of the four sections is an integer value that can be used for a specific purpose. The version number parts are:

  • Major Version. The major version number.
  • Minor Version. The minor version number.
  • Build Number. The build number.
  • Revision. The minor revision number.

The four components are combined into a full version number using full stop or period characters (.) as delimiters. For example, version 1.2.3.4 of an application would be major version one, minor version two, build three and revision four.

Usually the first release of a new piece of software is version 1.0.0.0. The major version number is only incremented if there is a substantial change in functionality or an entire rewrite of the software. The minor version may be incremented when new functionality is added or when a service pack containing multiple bug fixes is introduced. The build and revision numbers may be adjusted for minor fixes and cosmetic changes. However, these are only guidelines and other numbering methods are often used, including only maintaining and displaying the major and minor version numbers.

NB: Version numbers below 1.0.0.0 usually indicate an alpha or beta test release. Usually an increase in a version number element is accompanied by resetting more minor parts of the version to zero.

Setting the Version Number of a Program or Assembly

The version number of an assembly is set in the AssemblyInfo.cs file. This file contains various sections that allow information to be attributed to a Windows Forms project or any other type of assembly. To set the version of the assembly, the AssemblyVersion section is modified. For example, to set a version of 1.2.3.4, the following code would be used:

[assembly: AssemblyVersion("1.2.3.4")]

Automatic Numbering

Often the build and revision numbers are unused for an application's visible version number. If you decide not to set these values explicitly, you can elect to replace them with an asterisk (*). In this case, the compiler will automatically allocate random revision numbers and, optionally, build numbers. To use automatic numbering, use one of the following styles of assembly version declaration:

[assembly: AssemblyVersion("1.2.3.*")]
[assembly: AssemblyVersion("1.2.*")]

AssemblyFileVersion and AssemblyInformationalVersion Attributes

Visual Studio 2003 automatically adds an AssemblyVersion declaration to the AssemblyInfo.cs file. Later versions of Visual Studio also add an AssemblyFileVersion attribute by default. The AssemblyInfo attribute determines the internal version number of the assembly and is used by the .NET framework when loading assemblies. The AssemblyFileVersion attribute sets a version number for the file that is created. If the AssemblyFileVersion attribute is not declared, its value is set that to match the AssemblyVersion.

[assembly: AssemblyFileVersion("1.0.1.2")]

A third version attribute can be declared. The AssemblyInformationalVersion attribute can be used to store a version number or description. This version is for documentation purposes only and is not used by the .NET framework. If the AssemblyInformationalVersion attribute is not declared, its value is set that to match the AssemblyFileVersion.

[assembly: AssemblyInformationalVersion("1.2.0.5")]

Retrieving the Version Number

It can be useful to display the version number of an application to the user so that they can report the version that they are using for support purposes. In corporate scenarios where only one version should be in live use, this can identify an incorrect installation. For public installations where multiple versions are live, it can be essential to identify the version that is in use.

Application.ProductVersion Property

The full version number of a Windows Forms application can be retrieved using the static ProductVersion property of the Application object. This property returns a string containing the entire version number. For our earlier example with an informational version number of 1.2.0.0, the following example can be tested.

Console.WriteLine(Application.ProductVersion);              // Outputs 1.2.0.5

Version Class

The Version class is designed to hold version information. It includes properties for each of the four elements of a version number. The class includes a constructor that accepts a correctly formatted version number string, allowing the Application.Version property value to be easily converted to a Version object.

Version version = new Version(Application.ProductVersion);
Console.WriteLine(version.Major);                           // Outputs 1
Console.WriteLine(version.Minor);                           // Outputs 2
Console.WriteLine(version.Build);                           // Outputs 0
Console.WriteLine(version.Revision);                        // Outputs 5
25 March 2008