翻訳への提案を行います
 
他のユーザーによる提案:

progress indicator
他の提案はありません。
クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 4
.NET Framework ツール
 Ilasm.exe (MSIL アセンブラー)
すべて縮小/すべて展開 すべて縮小
コンテンツの表示:   英語と日本語を並べて表示コンテンツの表示: 英語と日本語を並べて表示
.NET Framework 4
Ilasm.exe (MSIL Assembler)

Updated: April 2011

The MSIL Assembler generates a portable executable (PE) file from Microsoft intermediate language (MSIL). (For more information on MSIL, see Managed Execution Process.) You can run the resulting executable, which contains MSIL and the required metadata, to determine whether the MSIL performs as expected.

This tool is automatically installed with Visual Studio and with the Windows SDK. To run the tool, we recommend that you use the Visual Studio Command Prompt or the Windows SDK Command Prompt (CMD Shell). These utilities enable you to run the tool easily, without navigating to the installation folder. For more information, see Visual Studio and Windows SDK Command Prompts.

  • If you have Visual Studio installed on your computer: On the taskbar, click Start, click All Programs, click Visual Studio, click Visual Studio Tools, and then click Visual Studio Command Prompt.

    -or-

    If you have the Windows SDK installed on your computer: On the taskbar, click Start, click All Programs, click the folder for the Windows SDK, and then click Command Prompt (or CMD Shell).

  • At the command prompt, type the following:

ilasm [options] filename [[options]filename...]

Argument

Description

filename

The name of the .il source file. This file consists of metadata declaration directives and symbolic MSIL instructions. Multiple source file arguments can be supplied to produce a single PE file with Ilasm.exe.

NoteNote
Ensure that the last line of code in the .il source file has either trailing white space or an end-of-line character.

Option

Description

/alignment=integer

Sets FileAlignment to the value specified by integer in the NT Optional header. If the .alignment IL directive is specified in the file, this option overrides it.

/base=integer

Sets ImageBase to the value specified by integer in the NT Optional header. If the .imagebase IL directive is specified in the file, this option overrides it.

/clock

Measures and reports the following compilation times in milliseconds for the specified .il source file:

Total Run: The total time spent performing all the specific operations that follow.

Startup: Loading and opening the file.

Emitting MD: Emitting metadata.

Ref to Def Resolution: Resolving references to definitions in the file.

CEE File Generation: Generating the file image in memory.

PE File Writing: Writing the image to a PE file.

/debug[=IMPL|OPT]

Includes debug information (local variable and argument names, and line numbers). Creates a PDB file.

/debug with no additional value disables JIT optimization and uses sequence points from the PDB file.

IMPL disables JIT optimization and uses implicit sequence points.

OPT enables JIT optimization and uses implicit sequence points.

IMPL and OPT are new in the .NET Framework version 2.0.

/dll

Produces a .dll file as output.

/enc=file

Creates Edit-and-Continue deltas from the specified source file.

This argument is for academic use only and is not supported for commercial use.

New in the .NET Framework version 2.0.

/exe

Produces an executable file as output. This is the default.

/flags=integer

Sets ImageFlags to the value specified by integer in the common language runtime header. If the .corflags IL directive is specified in the file, this option overrides it. See CorHdr.h , COMIMAGE_FLAGS for a list of valid values for integer.

/fold

Folds identical method bodies into one.

New in the .NET Framework version 2.0.

/include=includePath

Sets a path to search for files included with #include.

New in the .NET Framework version 2.0.

/itanium

Specifies Intel Itanium as the target processor.

If no image bitness is specified, the default is /pe64.

New in the .NET Framework version 2.0.

/key:keyFile

Compiles filename with a strong signature using the private key contained in keyFile.

/key:@keySource

Compiles filename with a strong signature using the private key produced at keySource.

/listing

Produces a listing file on the standard output. If you omit this option, no listing file is produced.

This parameter is not supported in .NET Framework version 2.0 or later.

/mdv=versionString

Sets the metadata version string.

New in the .NET Framework version 2.0.

/msv=major.minor

Sets the metadata stream version, where major and minor are integers.

New in the .NET Framework version 2.0.

/noautoinherit

Disables default inheritance from Object when no base class is specified.

New in the .NET Framework version 2.0.

/nocorstub

Suppresses generation of the CORExeMain stub.

New in the .NET Framework version 2.0.

/nologo

Suppresses the Microsoft startup banner display.

/output:file.ext

Specifies the output file name and extension. By default, the output file name is the same as the name of the first source file. The default extension is .exe. If you specify the /dll option, the default extension is .dll.

NoteNote
Specifying /output:myfile.dll does not set the /dll option. If you do not specify /dll, the result will be an executable file named myfile.dll.

/optimize

Optimizes long instructions to short. For example, br to br.s.

New in the .NET Framework version 2.0.

/pe64

Creates a 64-bit image (PE32+).

If no target processor is specified, the default is /itanium.

New in the .NET Framework version 2.0.

/pdb

Creates a PDB file without enabling debug information tracking.

New in the .NET Framework version 2.0.

/quiet

Specifies quiet mode; does not report assembly progress.

/resource:file.res

Includes the specified resource file in *.res format in the resulting .exe or .dll file. Only one .res file can be specified with the /resource option.

/stack=stackSize

Sets the SizeOfStackReserve value in the NT Optional header to stackSize.

New in the .NET Framework version 2.0.

/stripreloc

Specifies that no base relocations are needed.

New in the .NET Framework version 2.0.

/subsystem=integer

Sets subsystem to the value specified by integer in the NT Optional header. If the .subsystem IL directive is specified in the file, this command overrides it. See winnt.h, IMAGE_SUBSYSTEM for a list of valid values for integer.

/x64

Specifies a 64-bit AMD processor as the target processor.

If no image bitness is specified, the default is /pe64.

New in the .NET Framework version 2.0.

/?

Displays command syntax and options for the tool.

NoteNote

All options for Ilasm.exe are case-insensitive and recognized by the first three letters. For example, /lis is equivalent to /listing and /res:myresfile.res is equivalent to /resource:myresfile.res. Options that specify arguments accept either a colon (:) or an equal sign (=) as the separator between the option and the argument. For example, /output:file.ext is equivalent to /output=file.ext.

The MSIL Assembler helps tool vendors design and implement MSIL generators. Using Ilasm.exe, tool and compiler developers can concentrate on MSIL and metadata generation without being concerned with emitting MSIL in the PE file format.

Similar to other compilers that target the runtime, such as C# and Visual Basic, Ilasm.exe does not produce intermediate object files and does not require a linking stage to form a PE file.

The MSIL Assembler can express all the existing metadata and MSIL features of the programming languages that target the runtime. This allows managed code written in any of these programming languages to be adequately expressed in MSIL Assembler and compiled with Ilasm.exe.

NoteNote

Compilation might fail if the last line of code in the .il source file does not have either trailing white space or an end-of-line character.

You can use Ilasm.exe in conjunction with its companion tool, Ildasm.exe. Ildasm.exe takes a PE file that contains MSIL code and creates a text file suitable as input to Ilasm.exe. This is useful, for example, when compiling code in a programming language that does not support all the runtime metadata attributes. After compiling the code and running the output through Ildasm.exe, the resulting MSIL text file can be hand-edited to add the missing attributes. You can then run this text file through the Ilasm.exe to produce a final executable file.

You can also use this technique to produce a single PE file from several PE files originally generated by different compilers.

NoteNote

Currently, you cannot use this technique with PE files that contain embedded native code (for example, PE files produced by Visual C++).

To make this combined use of Ildasm.exe and Ilasm.exe as accurate as possible, the assembler does not perform some simple optimizations — it does not deduce whether to use short or long forms of instructions. For example, the tool does not try to determine whether it could substitute a short encoding for a long one you might have written in your MSIL sources (or that might be emitted by another compiler). If you want the short encoding, you must explicitly write that form. However, the assembler does check for out-of-range conditions where this is possible.

NoteNote

Ildasm.exe only operates on files on disk. It does not operate on files installed in the global assembly cache.

For more information about the grammar of MSIL, see the asmparse.grammar file in the Windows Software Development Kit (SDK).

The following command assembles the MSIL file myTestFile.il and produces the executable myTestFile.exe.

ilasm myTestFile

The following command assembles the MSIL file myTestFile.il and produces the .dll file myTestFile.dll.

ilasm myTestFile /dll 

The following command assembles the MSIL file myTestFile.il and produces the .dll file myNewTestFile.dll.

ilasm myTestFile /dll /output:myNewTestFile.dll

The following code example shows an extremely simple application that displays "Hello World!" to the console. You can compile this code and then use the Ildasm.exe tool to generate an MSIL file.

C#
using System;
public class Hello
{
    public static void Main(String[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

The following MSIL code example corresponds to the previous C# code example. You can compile this code into an assembly using the Ilasm.exe (MSIL Assembler) tool. Both MSIL and C# code examples display "Hello World!" to the console.

// Metadata version: v2.0.50215
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly sample
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module sample.exe
// MVID: {A224F460-A049-4A03-9E71-80A36DBBBCD3}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x02F20000


// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit Hello
       extends [mscorlib]System.Object
{
  .method public hidebysig static void  Main(string[] args) cil managed
  {
    .entrypoint
    // Code size       13 (0xd)
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldstr      "Hello World!"
    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_000b:  nop
    IL_000c:  ret
  } // end of method Hello::Main

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // Code size       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Hello::.ctor

} // end of class Hello

Date

History

Reason

April 2011

Added information about using the Visual Studio and Windows SDK Command Prompts.

Information enhancement.

.NET Framework 4
Ilasm.exe (MSIL アセンブラー)

更新 : 2011 年 4 月

MSIL アセンブラーは、ポータブル実行可能 (PE) ファイルを MSIL (Microsoft Intermediate Language) から生成します。 MSIL の詳細については、「マネージ実行プロセス」を参照してください。 MSIL と必要なメタデータを含む実行可能ファイルを実行すると、MSIL が予測どおりに動作するかどうかを確認できます。

このツールは Visual Studio および Windows SDK と一緒に自動的にインストールされます。 このツールを実行するには、Visual Studio コマンド プロンプトまたは Windows SDK コマンド プロンプト (CMD シェル) を使用することをお勧めします。 これらのユーティリティを使用すると、インストール フォルダーに移動することなくツールを簡単に実行できます。 詳細については、「Visual Studio と Windows SDK のコマンド プロンプト」を参照してください。

  • コンピューターに Visual Studio がインストールされている場合は、タスク バーの [Start] ボタンをクリックし、[All Programs]、[Visual Studio]、[Visual Studio Tools]、[Visual Studio Command Prompt] の順にクリックします。

    または

    コンピューターに Windows SDK がインストールされている場合は、タスク バーの [Start] ボタンをクリックし、[All Programs]、Windows SDK のフォルダー、[Command Prompt] (または [CMD Shell]) の順にクリックします。

  • コマンド プロンプトに次のように入力します。

ilasm [options] filename [[options]filename...]

引数

説明

filename

.il ソース ファイルの名前。 このファイルは、メタデータ宣言ディレクティブとシンボリック MSIL 命令で構成されます。 複数のソース ファイル引数を指定すると、Ilasm.exe で 1 つの PE ファイルを作成できます。

メモメモ
.il ソース ファイルのコードの最後の行に、後続の空白または行末文字のいずれかがあることを確認してください。

オプション

説明

/alignment=integer

NT オプション ヘッダーの FileAlignment を integer で指定された値に設定します。 このオプションは、ファイル指定されている .alignment IL ディレクティブをオーバーライドします。

/base=integer

NT オプション ヘッダーの ImageBase を integer で指定された値に設定します。 このオプションは、ファイルに指定されている .imagebase IL ディレクティブをオーバーライドします。

/clock

指定した .il ソース ファイルのコンパイル時間を計測して報告します。

Total Run: 後に続く特定の操作の実行に要した合計時間。

Startup: ファイルの読み込みとオープン。

Emitting MD: メタデータの生成。

Ref to Def Resolution: ファイルの定義への参照の解決。

CEE File Generation: メモリ内のファイル イメージの生成。

PE File Writing: PE へのイメージの書き込み。

/debug[=IMPL|OPT]

デバッグ情報 (ローカル変数と引数名、および行番号) を組み込みます。 PDB ファイルを作成します。

/debug に値を追加しなければ、JIT の最適化が無効になり、PDB ファイルのシーケンス ポイントが使用されます。

IMPL を指定すると、JIT 最適化が無効になり、暗黙のシーケンス ポイントが使用されます。

OPT を指定すると、JIT 最適化が有効になり、暗黙のシーケンス ポイントが使用されます。

IMPL 属性と OPT 属性は .NET Framework Version 2.0 で新たに追加されました。

/dll

出力として .dll ファイルを生成します。

/enc=file

指定されたソース ファイルからエディット コンティニュ デルタを作成します。

この引数は教育機関専用のため、商業目的の使用はサポートされていません。

.NET Framework Version 2.0 で新たに追加されました。

/exe

出力として実行可能ファイルを生成します。 これは、既定の設定です。

/flags=integer

共通言語ランタイム ヘッダーの ImageFlags を integer で指定された値に設定します。 このオプションは、ファイルに指定されている .corflags IL ディレクティブをオーバーライドします。 有効な integer の値の一覧については、CorHdr.h で COMIMAGE_FLAGS を参照してください。

/fold

複数の同じメソッド本体を 1 つに折りたたみます。

.NET Framework Version 2.0 で新たに追加されました。

/include=includePath

#include によってインクルードされるファイルの検索パスを設定します。

.NET Framework Version 2.0 で新たに追加されました。

/itanium

ターゲット プロセッサとして Intel Itanium を指定します。

イメージのビット数を指定しない場合、既定は /pe64 です。

.NET Framework Version 2.0 で新たに追加されました。

/key:keyFile

keyFile に含まれる秘密キーを使用して、厳密な署名を持つ filename をコンパイルします。

/key:@keySource

keySource で生成された秘密キーを使用して、厳密な署名を持つ filename をコンパイルします。

/listing

標準出力にリスティング ファイルを生成します。 このオプションを省略すると、リスティング ファイルは生成されません。

このパラメーターは、.NET Framework Version 2.0 以降ではサポートされません。

/mdv=versionString

メタデータのバージョン文字列を設定します。

.NET Framework Version 2.0 で新たに追加されました。

/msv=major.minor

メタデータのストリーム バージョンを設定します。ここで、majorminor は整数です。

.NET Framework Version 2.0 で新たに追加されました。

/noautoinherit

基本クラスが指定されていない場合、Object からの既定の継承を無効にします。

.NET Framework Version 2.0 で新たに追加されました。

/nocorstub

CORExeMain スタブの生成を抑止します。

.NET Framework Version 2.0 で新たに追加されました。

/nologo

Microsoft 著作権情報を表示しません。

/output:file.ext

出力ファイルの名前と拡張子を指定します。 既定では、出力ファイルの名前は最初のソース ファイルの名前と同じです。 既定の拡張子は .exe です。 /dll オプションを指定した場合の既定の拡張子は .dll です。

メモメモ
/output:myfile.dll と指定しても /dll オプションは設定されません。 /dll を指定しないと、myfile.dll という名前の実行可能ファイルになります。

/optimize

長いインストラクションを短く最適化します。 たとえば brbr.s にします。

.NET Framework Version 2.0 で新たに追加されました。

/pe64

64 ビットのイメージ (PE32+) を作成します。

ターゲット プロセッサを指定しない場合、既定は /itanium です。

.NET Framework Version 2.0 で新たに追加されました。

/pdb

デバッグ情報の追跡を有効にせずに PDB ファイルを作成します。

.NET Framework Version 2.0 で新たに追加されました。

/quiet

クワイエット モードを指定します。アセンブリの進行状況はレポートされません。

/resource:file.res

指定した *.res 形式のリソース ファイルを生成される .exe ファイルまたは .dll ファイルに組み込みます。 /resource オプションで指定できる .res ファイルは 1 つだけです。

/stack=stackSize

NT Optional ヘッダーの SizeOfStackReserve 値を stackSize に設定します。

.NET Framework Version 2.0 で新たに追加されました。

/stripreloc

ベースの再配置が不要であることを指定します。

.NET Framework Version 2.0 で新たに追加されました。

/subsystem=integer

NT オプション ヘッダーのサブシステムを integer で指定された値に設定します。 このコマンドは、ファイルに指定されている .subsystem IL ディレクティブをオーバーライドします。 有効な integer の値の一覧については、winnt.h で IMAGE_SUBSYSTEM を参照してください。

/x64

ターゲット プロセッサとして 64 ビットの AMD プロセッサを指定します。

イメージのビット数を指定しない場合、既定は /pe64 です。

.NET Framework Version 2.0 で新たに追加されました。

/?

このツールのコマンド構文とオプションを表示します。

メモメモ

Ilasm.exe に関するすべてのオプションでは大文字と小文字が区別されず、先頭の 3 文字で認識されます。 たとえば、/lis /listing と等価であり、/res:myresfile.res は /resource:myresfile.res と等価です。 引数を伴うオプションの場合は、オプションと引数の間に区切り記号としてコロン (:) または等号 (=) を挿入できます。 たとえば、/output:file.ext/output=file.ext と等価です。

MSIL アセンブラーは、MSIL ジェネレーターを設計および実装するツールの販売元を支援します。 ツールとコンパイラの開発者は、Ilasm.exe を使用することで、PE ファイル形式での MSIL の出力にかかわることなく、MSIL とメタデータの生成に集中できます。

C# および Visual Basic など、ランタイムを対象とした他のコンパイラと同様に、Ilasm.exe も中間オブジェクト ファイルを生成しません。このため、PE ファイルを形成するためのリンク ステージが必要ありません。

MSIL アセンブラーは、すべての既存メタデータ、およびランタイムを対象としたプログラミング言語の MSIL 機能を表現できます。 このため、このようなプログラミング言語で記述されたマネージ コードを MSIL アセンブラーで適切に表現し、Ilasm.exe でコンパイルできます。

メモメモ

.il ソース ファイルのコードの最後の行に、後続の空白または行末文字がない場合、コンパイルに失敗することがあります。

Ilasm.exe と、その対をなすツール Ildasm.exe を併用できます。 Ildasm.exe は、MSIL コードを含む PE ファイルを使用して、Ilasm.exe への入力として適したテキスト ファイルを作成します。 これは、必ずしもランタイム メタデータ属性のすべてをサポートしないプログラミング言語で記述されたコードをコンパイルするときなどに便利です。 コードをコンパイルし、その出力を Ildasm.exe で実行した後、生成された MSIL テキスト ファイルを手作業で編集して足りない属性を追加できます。 このテキスト ファイルを Ilasm.exe で実行すると、最終的な実行可能ファイルを生成できます。

この方法を使用して、異なるコンパイラによって生成された複数の PE ファイルから 1 つの PE ファイルを生成することもできます。

メモメモ

現時点では、埋め込みのネイティブ コード (たとえば Visual C++ で生成された PE ファイル) を含む PE ファイルについては、この手法を使用できません。

Ildasm.exe と Ilasm.exe を組み合わせて使用するときの処理をできる限り正確にするため、アセンブラーではある種の単純な最適化処理が実行されません。具体的には、短形式または長形式の命令を使用するかどうかが推測されません。 たとえば、長形式のエンコードがユーザーによって MSIL ソース内に書き込まれた (または他のコンパイラによって出力された) 場合でも、アセンブラーは長形式のエンコードを短形式で代替できるかどうかを判断しません。 短形式のエンコードが望ましい場合は、明示的に短形式で書く必要があります。 ただし、可能な場合は、アセンブラーは範囲外条件に関するチェックを実行します。

メモメモ

Ildasm.exe はディスク上のファイルについてだけ動作します。 グローバル アセンブリ キャッシュ内にインストールされたファイルについては動作しません。

MSIL の文法の詳細については、Windows Software Development Kit (SDK) の asmparse.grammar ファイルを参照してください。

MSIL ファイル myTestFile.il をアセンブルして実行可能ファイル myTestFile.exe. を生成するコマンドを次に示します。

ilasm myTestFile

MSIL ファイル myTestFile.il をアセンブルして .dll ファイル myTestFile.dll を生成するコマンドを次に示します。

ilasm myTestFile /dll 

MSIL ファイル myTestFile.il をアセンブルして .dll ファイル myNewTestFile.dll を生成するコマンドを次に示します。

ilasm myTestFile /dll /output:myNewTestFile.dll

コンソールに "Hello World!" を表示する簡単なアプリケーションのコード例を次に示します。 このコードのコンパイル後に Ildasm.exe ツールを使用して、MSIL ファイルを生成できます。

C#
using System;
public class Hello
{
    public static void Main(String[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

次の MSIL コードの例は、前の C# のコード例に対応しています。 Ilasm.exe (MSIL アセンブラー) ツールを使用すると、このコードをアセンブリにコンパイルできます。 MSIL コードと C# コードの例は、共にコンソールに "Hello World!" を表示します。

// Metadata version: v2.0.50215
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly sample
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module sample.exe
// MVID: {A224F460-A049-4A03-9E71-80A36DBBBCD3}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x02F20000


// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit Hello
       extends [mscorlib]System.Object
{
  .method public hidebysig static void  Main(string[] args) cil managed
  {
    .entrypoint
    // Code size       13 (0xd)
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldstr      "Hello World!"
    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_000b:  nop
    IL_000c:  ret
  } // end of method Hello::Main

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // Code size       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Hello::.ctor

} // end of class Hello

日付

履歴

理由

2011 年 4 月

Visual Studio と Windows SDK のコマンド プロンプトの使用に関する情報を追加。

情報の拡充

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