Windows Dev Center

AssemblyName.Version Property

Gets or sets the major, minor, build, and revision numbers of the assembly.

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

public Version Version { get; set; }

Property Value

Type: System.Version
The major, minor, build, and revision numbers of the assembly.

All components of the version must be integers greater than or equal to zero. Metadata restricts the major, minor, build, and revision components for an assembly to a maximum value of UInt16.MaxValue - 1. If a component exceeds this value, no error is thrown; however, in a dynamic assembly, that component is zero.

This section contains two examples. The first example shows how to use the AssemblyName(String) constructor to parse a string that contains a full assembly name. The second example shows how to create an assembly name and use it to define a dynamic assembly.

Example 1

The following example gets the full name of a .NET Framework assembly, parses it by using the AssemblyName(String) constructor, and uses the properties and methods of AssemblyName to display the individual parts.

using System;
using System.Reflection;

public class Example
   private const byte mask = 15;
   private const string hex = "0123456789ABCDEF";

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // Use AssemblyName to parse full assembly names. In this example, the 
      // assembly is mscorlib.dll.
      string name = typeof(string).Assembly.FullName;
      AssemblyName asmName = new AssemblyName(name);

      outputBlock.Text += String.Format("Name: {0}\n", asmName.Name);

      outputBlock.Text += String.Format("Version: {0}\n", asmName.Version);

      outputBlock.Text += String.Format("CultureInfo: {0}\n", asmName.CultureInfo);

      System.Text.StringBuilder pkt = new System.Text.StringBuilder();
      foreach( byte b in asmName.GetPublicKeyToken() )
         pkt.Append(hex[b / 16 & mask]);
         pkt.Append(hex[b & mask]);
      outputBlock.Text += String.Format("PublicKeyToken: {0}\n", pkt.ToString());

      outputBlock.Text += String.Format("FullName: {0}\n", asmName.FullName);

/* This example produces output similar to the following:

Name: mscorlib
PublicKeyToken: 7CEC85D7BEA7798E
FullName: mscorlib, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Example 2

The following example emits a dynamic assembly. When the assembly is created, the Version property is used to specify version information for the assembly.

using System;
using System.Reflection;
using System.Reflection.Emit;

public class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // Create an AssemblyName, set its properties, and use it to define a dynamic
      // assembly.
      AssemblyName aName = new AssemblyName("MyDynamicAssembly");
      aName.CultureInfo = new System.Globalization.CultureInfo("en-US");
      aName.Version = new Version("");

      AssemblyBuilder ab = 
         AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
      ModuleBuilder mb = ab.DefineDynamicModule("Temp");
      TypeBuilder tb = mb.DefineType("Dummy", TypeAttributes.Public);

      Type t = tb.CreateType();

      outputBlock.Text += String.Format("Assembly FullName: {0}\n", t.Assembly.FullName);

/* This code example produces output similar to the following:

Assembly FullName: MyDynamicAssembly, Version=, Culture=en-US, PublicKeyToken=null

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2015 Microsoft