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.
Note |
|---|
| 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.
Note |
|---|
| 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.
Note |
|---|
| 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 .NET Framework SDK.