C#编译器生成的.exe文件是否仅由通用中间语言(CIL)组成?

前端之家收集整理的这篇文章主要介绍了C#编译器生成的.exe文件是否仅由通用中间语言(CIL)组成?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是想更好地掌握以下代码添加文件并使用.cs扩展名保存时在简单场景中发生的事情:
public class HelloWorld
{
  public static void Main()
  {
    System.Console.WriteLine("Hello World!");
    System.Console.ReadLine();
  }
}

然后这个程序在windows命令行运行:

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

我可以看到这个进程生成一个.exe文件,但是在阅读有关compile process on wikipedia时,它指出:

  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.

那么.exe文件本身只包含Common Intermediate Lanaguage吗?这个文件本身就是维基百科文章所称的’CLI程序集’吗?我有点困惑,因为我只能看到.exe文件,对我来说,’assembly’这个术语推断出多个文件.

相关问题:

>是Microsoft.NET目录中的JIT编译器,在执行.exe文件时,文件与JIT编译器通信,然后JIT编译器以本机代码输出指令?

解决方法

不,它没有.

可执行文件PE image.

有关详情,请参阅Anatomy of a .NET Assembly – PE Headers.

.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.

原文链接:https://www.f2er.com/csharp/97914.html

猜你在找的C#相关文章