简体   繁体   English

Roslyn 可以将 C# 编译为 CIL

[英]Can Roslyn compile C# to CIL

Can the Roslyn C# compiler be used to compile C# to CIL human readable code? Roslyn C# 编译器可以用于将 C# 编译为 CIL 人类可读代码吗? Like the examples shown here : https://en.wikipedia.org/wiki/Common_Intermediate_Language就像这里显示的例子: https : //en.wikipedia.org/wiki/Common_Intermediate_Language

I know it can produce bytecode in EXE/DLL form, but I'm interested in the CIL code.我知道它可以生成 EXE/DLL 形式的字节码,但我对 CIL 代码感兴趣。

Either from the command line or API.无论是从命令行还是 API。

I know a disassembler could be used on the bytecode files but I would prefer a more direct approach.我知道可以在字节码文件上使用反汇编程序,但我更喜欢更直接的方法。

Thanks.谢谢。

Simply call ildasm.exe as your post-build step.只需将 ildasm.exe 称为构建后步骤。 Solutions should be composable steps instead of one monolithic monstrosity.解决方案应该是可组合的步骤,而不是一个单一的怪物。

SharpLab can translate C#, Visual Basic, or F# on-the-fly to a number of formats, one of which is CIL. SharpLab可以将 C#、Visual Basic 或 F# 即时转换为多种格式,其中之一是 CIL。

It does so using Roslyn from the Roslyn repo and you can select which version you want it to use.它使用 Roslyn 存储库中的 Roslyn 来实现,您可以选择要使用的版本。

It's not an extension/command line tool/API, but it's likely to be very useful for anyone else trying to view CIL easily.它不是一个扩展/命令行工具/API,但对于任何试图轻松查看 CIL 的人来说可能非常有用。

C# is automatically compiled to CIL. C# 会自动编译为 CIL。 That is the target platform.那就是目标平台。 (*Not sure about .NET Native/UWP). (*不确定 .NET Native/UWP)。

Since it seems to me, that your goal is to show the generated CIL code, take a look at Msiler :在我看来,您的目标是显示生成的 CIL 代码,请查看Msiler

If you by chance use Resharper, there is an IL-Viewer included .如果您偶然使用 Resharper, 其中包含一个 IL-Viewer

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

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