8

I am just trying to get a better grasp on what happens in a simple scenario when the following code is added to a file and saved with the .cs extension:

public class HelloWorld
{
  public static void Main()
  {
    System.Console.WriteLine("Hello World!");
    System.Console.ReadLine();
  }
}

and then this program is run at the windows command line with:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc /t:exe /out:C:\HelloWorld\HelloWorld.exe C:\HelloWorld\HelloWorld.cs

I can see this process produces an .exe file, however when reading about the compile process on wikipedia it states:

  1. Source code is converted to Common Intermediate Language (CIL), which is the CLI's equivalent to Assembly language for a CPU.
  2. CIL is then assembled into a form of so-called bytecode and a CLI assembly is created.
  3. Upon execution of a CLI assembly, its code is passed through the runtime's JIT compiler to generate native code...
  4. The native code is executed by the computer's processor.

So does the .exe file itself consist solely of Common Intermediate Lanaguage? And is this file itself what the wikipedia article refers to as the 'CLI assembly'? I'm a bit confused because I can only see the .exe file and to me the term 'assembly' infers more than one file.

And related question:

  • is the JIT compiler somewhere in the Microsoft.NET directory and upon executing the .exe file the file communicates with the JIT compiler which then outputs the instructions in native code?
4

2 回答 2

13

No, it doesn't.

The executable is a PE image.

See Anatomy of a .NET Assembly – PE Headers for details.

.NET assemblies are built on top of the PE (Portable Executable) file format that is used for all Windows executables and dlls, which itself is built on top of the MSDOS executable file format. The reason for this is that when .NET 1 was released, it wasn’t a built-in part of the operating system like it is nowadays. Prior to Windows XP, .NET executables had to load like any other executable, had to execute native code to start the CLR to read & execute the rest of the file.

于 2013-07-17T13:08:49.647 回答
2

It calls assembly, because contains more then one semantic data:

  • code
  • manifest
  • 0 or more modules

If on any CLR assembly (EXE or DLL) you run simple tool like: DotPeek you will see IL instructions.

于 2013-07-17T13:09:45.583 回答