Is it possible to force JIT to compile an assembly and get asm code?

.net, .net-assembly, clr

Solution

What do you want to do with it? I don't think you can do this directly.

Assuming you have used Ngen for creating a native image, the native image cache should be at some path like

C:\Windows\assembly\NativeImages_v4.0.30319_32\

The exact path depends on the framework version and possibly some other factors and i don't think you have a guarantee that it will always be there. If you find your native image in there, you might be able to use a disassembler to look at the machine code.

Problem

Is there any way to get .NET compiled exe assembly, being disassembled to the pure assembler? Maybe there are some built in tools to achive this. I know that C# code is compiled into IL, and then in Runtime JIT compiles it machine code. The question is can I somehow force jit to compile to assembly and take this output for a text file for example. Or I am confused and my understanding of how the CLR works is wrong?

Original source