Can Roslyn compile C# to CIL

Viewed 1054

Can the Roslyn C# compiler be used to compile C# to CIL human readable code? Like the examples shown here : 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.

Either from the command line or API.

I know a disassembler could be used on the bytecode files but I would prefer a more direct approach.

Thanks.

3 Answers

SharpLab can translate C#, Visual Basic, or F# on-the-fly to a number of formats, one of which is CIL.

It does so using Roslyn from the Roslyn repo and you can select which version you want it to use.

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.

Related