Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System.Reflection
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
AssemblyVersionAttribute Class

Specifies the version of the assembly being attributed.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly, Inherited:=False)> _
Public NotInheritable Class AssemblyVersionAttribute
    Inherits Attribute
Visual Basic (Usage)
Dim instance As AssemblyVersionAttribute
C#
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false)] 
public sealed class AssemblyVersionAttribute : Attribute
C++
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly, Inherited=false)] 
public ref class AssemblyVersionAttribute sealed : public Attribute
J#
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) */ 
public final class AssemblyVersionAttribute extends Attribute
JScript
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) 
public final class AssemblyVersionAttribute extends Attribute

The assembly version number is part of an assembly's identity and plays a key part in binding to the assembly and in version policy. The default version policy for the runtime is that applications run only with the versions they were built and tested with, unless overridden by explicit version policy in configuration files (the application configuration file, the publisher policy file, and the computer's administrator configuration file). See Assemblies Overview for more information.

NoteNote

Version checking only occurs with strong-named assemblies.

The version number has four parts, as follows:

<major version>.<minor version>.<build number>.<revision>

You can specify all the values or you can accept the default build number, revision number, or both by using an asterisk (*). For example, [assembly:AssemblyVersion("2.3.25.1")] indicates 2 as the major version, 3 as the minor version, 25 as the build number, and 1 as the revision number. A version number such as [assembly:AssemblyVersion("1.2.*")] specifies 1 as the major version, 2 as the minor version, and accepts the default build and revision numbers. A version number such as [assembly:AssemblyVersion("1.2.15.*")] specifies 1 as the major version, 2 as the minor version, 15 as the build number, and accepts the default revision number. The default build number increments daily. The default revision number is random.

NoteNote

If you specify an asterisk for the build number, you cannot specify a revision number.

The assembly major and minor versions are used as the type library version number when the assembly is exported. Some COM hosts do not accept type libraries with the version number 0.0. Therefore, if you want to expose an assembly to COM clients, set the assembly version explicitly to 1.0 in the AssemblyVersionAttribute page for projects created outside Visual Studio 2005 and with no AssemblyVersionAttribute specified. Do this even when the assembly version is 0.0. All projects created in Visual Studio 2005 have a default assembly version of 1.0*.

To get the name of an assembly you have loaded, call GetName on the assembly to get an AssemblyName, and then get the Version property. To get the name of an assembly you have not loaded, call GetAssemblyName from your client application to check the assembly version that your application uses.

System.Object
   System.Attribute
    System.Reflection.AssemblyVersionAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Other ways to get the version of an assembly.      Randolpho   |   Edit   |   Show History

While you could use GetAssemblyName() as mentioned in the remarks above, this requires a filename path to the .dll or .exe file of the assembly, and that may not be available to you at runtime.
Often, when you want the version of an assembly, you're interested the overall version of a program; usually for display in an "about" dialog window. The overall version of a program is typically the Verson object associated with the process assembly, as opposed to the currently executing assembly. This can be obtained from the Assembly.GetEntryAssembly() method. Note, however, that if your program launches from unmanaged code, GetEntryAssembly will return null.

Example: [C#]

using System;
using System.Reflection;
 
public static Version GetProgramVersion()
{
  Assembly entry = Assembly.GetEntryAssembly();
  if(entry == null)
  {
    throw new Exception("Version unobtainable");
  }
  return entry.GetName().Version;
}

 

Tags What's this?: Add a tag
Flag as ContentBug
The AssemblyVersionAttribute is not really in the assembly      Paulo Morgado   |   Edit   |   Show History
The AssemblyVersionAttribute is converted in the AssemblyName.Version value of the assembly. You can't get it from Assembly.GetCustomAttributes.
Tags What's this?: Add a tag
Flag as ContentBug
How to use this attribute for consistent version numbering across multiple projects      Kristof Verbiest   |   Edit   |   Show History
There are several techniques on how to use this attribute to apply the same version-number to several projects. These techniques are listed here:
http://kristofverbiest.blogspot.com/2008/09/how-to-use-consistent-version-numbering.html
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker