Represents the version number of an assembly, operating system, or the common language runtime. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|Version()||Initializes a new instance of the class.|
|Version(String)||Initializes a new instance of the class using the specified string.|
|Version(Int32, Int32)||Initializes a new instance of the class using the specified major and minor values.|
|Version(Int32, Int32, Int32)||Initializes a new instance of the class using the specified major, minor, and build values.|
|Version(Int32, Int32, Int32, Int32)||Initializes a new instance of the class with the specified major, minor, build, and revision numbers.|
|Build||Gets the value of the build component of the version number for the current object.|
|Major||Gets the value of the major component of the version number for the current object.|
|MajorRevision||Gets the high 16 bits of the revision number.|
|Minor||Gets the value of the minor component of the version number for the current object.|
|MinorRevision||Gets the low 16 bits of the revision number.|
|Revision||Gets the value of the revision component of the version number for the current object.|
|Clone||Returns a new object whose value is the same as the current object.|
|CompareTo(Object)||Compares the current object to a specified object and returns an indication of their relative values.|
|CompareTo(Version)||Compares the current object to a specified object and returns an indication of their relative values.|
|Equals(Object)||Returns a value indicating whether the current object is equal to a specified object. (Overrides Object.Equals(Object).)|
|Equals(Version)||Returns a value indicating whether the current object and a specified object represent the same value.|
|GetHashCode||Returns a hash code for the current object. (Overrides Object.GetHashCode().)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|Parse||Converts the string representation of a version number to an equivalent object.|
|ToString()||Converts the value of the current object to its equivalent String representation. (Overrides Object.ToString().)|
|ToString(Int32)||Converts the value of the current object to its equivalent String representation. A specified count indicates the number of components to return.|
|TryParse||Tries to convert the string representation of a version number to an equivalent object, and returns a value that indicates whether the conversion succeeded.|
|Equality||Determines whether two specified objects are equal.|
|GreaterThan||Determines whether the first specified object is greater than the second specified object.|
|GreaterThanOrEqual||Determines whether the first specified object is greater than or equal to the second specified object.|
|Inequality||Determines whether two specified objects are not equal.|
|LessThan||Determines whether the first specified object is less than the second specified object.|
|LessThanOrEqual||Determines whether the first specified object is less than or equal to the second object.|
Version numbers consist of two to four components: major, minor, build, and revision. The major and minor components are required; the build and revision components are optional, but the build component is required if the revision component is defined. All defined components must be integers greater than or equal to 0. The format of the version number is as follows (optional components are shown in square brackets ([ and ]):
The components are used by convention as follows:
Major: Assemblies with the same name but different major versions are not interchangeable. A higher version number might indicate a major rewrite of a product where backward compatibility cannot be assumed.
Minor: If the name and major version number on two assemblies are the same, but the minor version number is different, this indicates significant enhancement with the intention of backward compatibility. This higher minor version number might indicate a point release of a product or a fully backward-compatible new version of a product.
Build: A difference in build number represents a recompilation of the same source. Different build numbers might be used when the processor, platform, or compiler changes.
Revision: Assemblies with the same name, major, and minor version numbers but different revisions are intended to be fully interchangeable. A higher revision number might be used in a build that fixes a security hole in a previously released assembly.
Subsequent versions of an assembly that differ only by build or revision numbers are considered to be Hotfix updates of the prior version.
Starting with .NET Framework 2.0, the MajorRevision and MinorRevision properties enable you to identify a temporary version of your application that, for example, corrects a problem until you can release a permanent solution. Furthermore, the Windows NT operating system uses the MajorRevision property to encode the service pack number.
Assigning Version Information to Assemblies
Ordinarily, the class is not used to assign a version number to an assembly. Instead, the AssemblyVersionAttribute class is used to define an assembly's version, as illustrated by the example in this topic.
Retrieving Version Information
objects are most frequently used to store version information about some system or application component (such as the operating system), the common language runtime, the current application's executable, or a particular assembly. The following examples illustrate some of the most common scenarios:
Retrieving the operating system version. The following example uses the OperatingSystem.Version property to retrieve the version number of the operating system.
Retrieving the version of the common language runtime. The following example uses the Environment.Version property to retrieve version information about the common language runtime.
Retrieving the current application's assembly version. The following example uses the Assembly.GetEntryAssembly method to obtain a reference to an Assembly object that represents the application executable and then retrieves its assembly version number.
Retrieving the current assembly's assembly version. The following example uses the Type.Assembly property to obtain a reference to an Assembly object that represents the assembly that contains the application entry point, and then retrieves its version information.
Retrieving the version of a specific assembly. The following example uses the Assembly.ReflectionOnlyLoadFrom method to obtain a reference to an Assembly object that has a particular file name, and then retrieves its version information. Note that several other methods also exist to instantiate an Assembly object by file name or by strong name.
Retrieving the Publish Version of a ClickOnce application. The following example uses the ApplicationDeployment.CurrentVersion property to display an application's Publish Version. Note that its successful execution requires the example's application identity to be set. This is handled automatically by the Visual Studio Publish Wizard.
The Publish Version of an application for ClickOnce deployment is completely independent of its assembly version.
Comparing Version Objects
You can use the CompareTo method to determine whether one object is earlier than, the same as, or later than a second object. The following example indicates that Version 2.1 is later than Version 2.0.
For two versions to be equal, the major, minor, build, and revision numbers of the first object must be identical to those of the second object. If the build or revision number of a object is undefined, that object is considered to be earlier than a object whose build or revision number is equal to zero. The following example illustrates this by comparing three objects that have undefined version components.
The following example uses the AssemblyVersionAttribute attribute to assign a version number to an assembly. At compile time, this version information is stored with the assembly's metadata. At run time, the example retrieves the value of the Type.Assembly property on a type found in the assembly to get a reference to the executing assembly, and it retrieves the assembly's version information from the Version property of the AssemblyName object returned by the Assembly.GetName method.