简体   繁体   English

对MSIL感到困惑

[英]Confused about MSIL

I read the c# program compilation takes two steps. 我阅读了C#程序的编译需要两个步骤。

First it generates MSIL and then it produces the machine code. 首先,它生成MSIL,然后生成机器代码。 So I am curious to see the files generated by first phase of compilation (MSIL). 所以我很好奇看到编译的第一阶段(MSIL)生成的文件。

I have been thinking the DLL file is the file which contains the MSIL code, but I think I am wrong. 我一直认为DLL文件是包含MSIL代码的文件,但我认为我错了。

You are right. 你是对的。 .NET DLL's and EXE's (called assemblies in .NET) are the ones that contain MSIL. .NET DLL和EXE(在.NET中称为程序集)是包含MSIL的文件。 DLL's can have another format than the .NET ones, so that's why the .NET assemblies have a header that makes them recognizable as such. DLL可以具有.NET以外的另一种格式,因此这就是.NET程序集具有标头使其可以被识别的原因。 You can use corflags.exe to check if an DLL/EXE is a .NET DLL/EXE. 您可以使用corflags.exe检查DLL / EXE是否为.NET DLL / EXE。

The IL code in the assembly is interpreted by the CLR (Common Language Runtime), which translates it to machine code. 程序集中的IL代码由CLR(公共语言运行时)解释,并将其转换为机器代码。 You can't see that step actually since it is done by the JIT'ter at runtime (or you should pre-compile the assemblies using ngen.exe and read the generated files). 您实际上看不到该步骤,因为它是在运行时由JIT'ter完成的(或者您应该使用ngen.exe预编译程序集并读取生成的文件)。

.net has multiple languages (C#, VB.net etc.). .net具有多种语言(C#,VB.net等)。

When you compile a C# project library, it outputs a dll that contains IL code. 当您编译C#项目库时,它将输出包含IL代码的dll。

C# compiles to IL as VB.net compiles to IL and therefore you can "mix up" code between to two languages. C#编译为IL,就像VB.net编译为IL一样,因此您可以在两种语言之间“混合”代码。

This IL is compiled to machine code using the JIT compiler in runtime (read about the CLR ). 在运行时使用JIT编译器将此IL编译为机器代码(了解CLR )。

You can see IL code by using a reflector and reflecting a dll. 您可以通过使用反射器并反射dll来查看IL代码。

Read more here . 在这里阅读更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM