クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System 名前空間
Version クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
Version クラス

更新 : 2008 年 7 月

共通言語ランタイム アセンブリのバージョン番号を表します。このクラスは継承できません。

名前空間 :  System
アセンブリ :  mscorlib (mscorlib.dll 内)
Visual Basic (宣言)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class Version _
    Implements ICloneable, IComparable, IComparable(Of Version),  _
    IEquatable(Of Version)
Visual Basic (使用法)
Dim instance As Version
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class Version : ICloneable, 
    IComparable, IComparable<Version>, IEquatable<Version>
Visual C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class Version sealed : ICloneable, 
    IComparable, IComparable<Version^>, IEquatable<Version^>
J#
/** @attribute SerializableAttribute */ 
/** @attribute ComVisibleAttribute(true) */
public final class Version implements ICloneable, 
    IComparable, IComparable<Version>, IEquatable<Version>
JScript
public final class Version implements ICloneable, IComparable, IComparable<Version>, IEquatable<Version>

Version オブジェクトを使用して、アセンブリのバージョン番号を格納および比較します。アセンブリのバージョン番号には、自分で、またはアプリケーションによって Version オブジェクトを設定できるので注意してください。ただし、Version オブジェクトは特定のアセンブリのバージョン番号に自動的には設定されません。Version クラスには、そのような情報を取得できるメンバが含まれていません。

バージョン番号は、メジャー、マイナ、ビルド、リビジョンなどの 2 ~ 4 つの構成要素で構成されます。メジャーおよびマイナ構成要素は必須です。ビルドおよびリビジョン構成要素は省略可能です。リビジョン構成要素を定義した場合は、ビルド構成要素も定義する必要があります。すべての構成要素は、0 以上の整数で定義する必要があります。バージョン番号の形式は、次のとおりです。省略可能な構成要素は、角かっこ ("[" および "]") で示します。

メジャー.マイナ[.ビルド[.リビジョン]]

通常使用される構成要素を次に示します。

  • メジャー : 名前は同じでも、メジャー バージョンが異なるアセンブリは互換性がありません。これは下位互換性を想定できない製品のメジャー リライトなどに当てはまります。

  • マイナ : 2 つのアセンブリにおいて、名前とメジャー番号が同じでも、マイナ番号が異なる場合は、下位互換性を目的とした大幅な改良が行われていることを示します。これは製品のポイント リリースや、完全下位互換の新しいバージョンの製品などに当てはまります。

  • ビルド : ビルド番号が異なる場合は、同一ソースの再コンパイルが行われたことを示します。これはプロセッサ、プラットフォーム、コンパイラなどが変更された場合に当てはまります。

  • リビジョン : 名前、メジャー バージョン番号、およびマイナ バージョン番号が同じで、リビジョンが異なるアセンブリは、完全互換を目的としています。これは前のリリースのアセンブリのセキュリティ ホールを修正する場合に当てはまります。

ビルド番号またはリビジョン番号だけが異なるアセンブリのバージョンは、前のバージョンのホットフィックス更新と見なされます。

.NET Framework 2.0 以上では、MajorRevision プロパティおよび MinorRevision プロパティを使用して、恒久的なソリューションをリリースするまでの間に問題を修正するアプリケーションのような、一時的なバージョンのアプリケーションを特定できます。さらに、Windows NT オペレーティング システムでは、MajorRevision プロパティを使用して、サービス パック番号をエンコードできます。

このクラスは、ICloneableIComparableIComparable<(Of <(T>)>)、および IEquatable<(Of <(T>)>) の各インターフェイスを実装しています。

アセンブリにバージョン情報を割り当てます。

通常、アセンブリにバージョン番号を割り当てるために Version クラスは使用されません。その代わりに、AssemblyVersionAttribute クラスを使用してアセンブリのバージョンを定義します。

バージョン情報の取得

Version オブジェクトは、オペレーティング システムなどの一部のシステム コンポーネントやアプリケーション コンポーネント、共通言語ランタイム、現在のアプリケーションの実行可能ファイル、または特定のアセンブリに関するバージョン情報を格納するために最も頻繁に使用されます。次の例に、最も一般的なシナリオの一部を示します。

  • オペレーティング システム バージョンの取得。次の例では、OperatingSystem..::.Version プロパティを使用してオペレーティング システムのバージョン番号を取得しています。

    Visual Basic
    ' Get the operating system version.
    Dim os As OperatingSystem = Environment.OSVersion
    Dim ver As Version = os.Version
    Console.WriteLine("Operating System: {0} ({1})", os.VersionString, ver.ToString())
    
    
    C#
    // Get the operating system version.
    OperatingSystem os = Environment.OSVersion;
    Version ver = os.Version;
    Console.WriteLine("Operating System: {0} ({1})", os.VersionString, ver.ToString());
    
    
  • 共通言語ランタイムのバージョンの取得。次の例では、Environment..::.Version プロパティを使用して共通言語ランタイムに関するバージョン情報を取得しています。

    Visual Basic
    ' Get the common language runtime version.
    Dim ver As Version = Environment.Version
    Console.WriteLine("CLR Version {0}", ver.ToString())
    
    
    C#
    // Get the common language runtime version.
    Version ver = Environment.Version;
    Console.WriteLine("CLR Version {0}", ver.ToString());
    
    
  • 現在のアプリケーションのバージョンの取得。次の例では、Assembly..::.GetEntryAssembly メソッドを使用して、アプリケーションの実行可能ファイルを表す Assembly オブジェクトへの参照を取得し、そのバージョン番号を取得しています。

    Visual Basic
    ' Get the version of the executing assembly (that is, this assembly).
    Dim assem As Assembly = Assembly.GetEntryAssembly()
    Dim assemName As AssemblyName = assem.GetName()
    Dim ver As Version = assemName.Version
    Console.WriteLine("Application {0}, Version {1}", assemName.Name, ver.ToString())
    
    
    C#
    // Get the version of the executing assembly (that is, this assembly).
    Assembly assem = Assembly.GetEntryAssembly();
    AssemblyName assemName = assem.GetName();
    Version ver = assemName.Version;
    Console.WriteLine("Application {0}, Version {1}", assemName.Name, ver.ToString());
    
    
  • 現在のアセンブリのバージョンの取得。次の例では、Assembly..::.GetExecutingAssembly メソッドを使用して、現在のアセンブリを表す Assembly オブジェクトへの参照を取得し、そのバージョン情報を取得しています。

    Visual Basic
    ' Get the version of the current application.
    Dim assem As Assembly = Assembly.GetExecutingAssembly()
    Dim assemName As AssemblyName = assem.GetName()
    Dim ver As Version = assemName.Version
    Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString())
    
    
    C#
    // Get the version of the current application.
    Assembly assem = Assembly.GetExecutingAssembly();
    AssemblyName assemName = assem.GetName();
    Version ver = assemName.Version;
    Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString());
    
    
  • 特定のアセンブリのバージョンの取得。次の例では、Assembly..::.ReflectionOnlyLoadFrom メソッドを使用して、特定のファイル名を含む Assembly オブジェクトへの参照を取得し、そのバージョン情報を取得しています。Assembly オブジェクトをファイル名または厳密な名前でインスタンス化するには、その他にも複数のメソッドがあります。

    Visual Basic
    ' Get the version of a specific assembly.
    Dim filename As String = ".\StringLibrary.dll"
    Dim assem As Assembly = Assembly.ReflectionOnlyLoadFrom(filename)
    Dim assemName As AssemblyName = assem.GetName()
    Dim ver As Version = assemName.Version
    Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString())
    
    
    C#
    // Get the version of a specific assembly.
    string filename = @".\StringLibrary.dll";
    Assembly assem = Assembly.ReflectionOnlyLoadFrom(filename);
    AssemblyName assemName = assem.GetName();
    Version ver = assemName.Version;
    Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString());
    
    

Assembly クラスを使用してアセンブリを識別する Version オブジェクトを取得するコード例を次に示します。

Visual Basic
' This code example demonstrates the Version class.
' 
'   This code example loads an assembly and retrieves its 
'   version number. 
'   Typically, you would use code similar to this example 
'   to load a separate assembly and obtain its version number. 
'   However, solely to avoid using another assembly, this code 
'   example loads itself and retrieves its own version number. 
'
'   This code example is created in two steps:
'1) The AssemblyVersionAttribute attribute is applied to this 
'   code example at the assembly level. Then the code example 
'   is compiled into the MyAssembly.exe executable assembly.
'2) When MyAssembly.exe is executed, it loads itself, then 
'   displays its own version number. 

Imports System
Imports System.Reflection

' Apply the version number, 1.2.3.4, to this assembly.
<assembly:AssemblyVersionAttribute("1.2.3.4")>
Class Sample
    Public Shared Sub Main() 

' Use the Assembly class to load MyAssembly.exe. Note that
' the name of the assembly does not include the ".exe" suffix
' of the executable file.
        Dim myAsm As Assembly = Assembly.Load("MyAssembly")
        Dim aName As AssemblyName = myAsm.GetName()

' Store the version number in a Version object.
        Dim ver As Version = aName.Version

' Display the version number of MyAssembly.
        Console.WriteLine(ver)
    End Sub 'Main
End Class 'Sample

'This code example produces the following results:
'
'1.2.3.4
'

C#
// This code example demonstrates the Version class.

/* 
   This code example loads an assembly and retrieves its 
   version number. 
   Typically, you would use code similar to this example 
   to load a separate assembly and obtain its version number. 
   However, solely to avoid using another assembly, this code 
   example loads itself and retrieves its own version number. 

   This code example is created in two steps:
1) The AssemblyVersionAttribute attribute is applied to this 
   code example at the assembly level. Then the code example 
   is compiled into the MyAssembly.exe executable assembly.
2) When MyAssembly.exe is executed, it loads itself, then 
   displays its own version number. 
*/

using System;
using System.Reflection;

// Apply the version number, 1.2.3.4, to this assembly.
[assembly:AssemblyVersionAttribute("1.2.3.4")]
class Sample 
{
    public static void Main() 
    {
// Use the Assembly class to load MyAssembly.exe. Note that
// the name of the assembly does not include the ".exe" suffix
// of the executable file.

    Assembly myAsm = Assembly.Load("MyAssembly");
    AssemblyName aName = myAsm.GetName();

// Store the version number in a Version object.
    Version ver = aName.Version;

// Display the version number of MyAssembly.
    Console.WriteLine(ver);
    }
}

/*
This code example produces the following results:

1.2.3.4

*/

System..::.Object
  System..::.Version
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

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

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 3.5、2.0、1.0

XNA Framework

サポート対象 : 2.0、1.0

日付

履歴

理由

2008 年 7 月

バージョン情報の割り当ておよび取得に関するセクションを「解説」に追加。

カスタマ フィードバック

コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker