如何查看 C# 编译器生成的 MSIL/CIL?为什么叫汇编? [英] How can I view MSIL / CIL generated by C# compiler? Why is it called assembly?
本文介绍了如何查看 C# 编译器生成的 MSIL/CIL?为什么叫汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 .NET C# 编程的新手.我正在关注几本书.据说不是将 C# 代码直接编译为机器代码,而是将其转换为中间语言(称为 MSIL 又名 CIL).但是当我编译时,我得到了一个 exe/dll 文件.
I'm new to .NET C# programming. I'm following few books. It is said that instead of compiling C# code directly to machine code, it is converted into an intermediate language (called MSIL aka CIL). But when I compile, I get an exe/dll file.
- 这些 exe/dll 文件中是否包含此 MSIL/CIL?
- 我想看看那个中间语言代码,只是为了感受一下它的存在.如何查看?
- 他们将这个 exe/dll 文件称为
assembly
.他们是否在使用这个花哨的词"?只是为了将它们与包含本机/机器代码的 exe/dll 文件区分开来?
- Is this MSIL/CIL contained in these exe/dll files?
- I want to see that intermediate language code, just to get feel for its existence. How do I view it?
- They are calling this exe/dll file an
assembly
. Are they using this "fancy word" just to differentiate these from the exe/dll files that contain native/machine code?
推荐答案
- 是的,更确切地说是在 PE 的
.text
部分文件(便携式可执行文件 = *.exe 或 *.dll).可以在此处找到更多信息. - 最好的选择是使用 ILSpy(Reflector 不再免费).它是一个免费的反汇编程序,可以将您的程序集反汇编为 MSIL 以及 C#、VB(在某种程度上)..NET Framework SDK 包含 ILDasm,它是官方的 MSIL 反汇编程序.
- 基本上是的.程序集是包含 MSIL 代码和相应元数据的文件.这不仅限于 PE 文件本身,而是所有当前的 CLR 实现都使用它们.
- Yes it is, more exactly in the
.text
section of the PE file (portable executable = *.exe or *.dll). More information can be found here. - The best choice is to use ILSpy (Reflector is no longer free). It's a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). The .NET Framework SDK contains ILDasm, which is the official MSIL dissasembler.
- Basically yes. An assembly is a file that contains MSIL code and corresponding metadata. This is not restricted to PE files per se, but all current CLR implementations use them.
如果我也可以推荐一本关于这方面的好书,那就是 Serge Lidin 的 Expert .NET 2.0 IL Assembler.他是设计 MSIL 的人.
If I may recommend a good book on that matter too, it's Expert .NET 2.0 IL Assembler by Serge Lidin. He's the guy who designed MSIL.
这篇关于如何查看 C# 编译器生成的 MSIL/CIL?为什么叫汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文