Getting the compiled asm of a c# program [duplicate]
Possible Duplicate:
Retrieve JIT output
Is this possible to do, and if so how (I would need to be after its JITed i think, but I have no idea how to go about doing this)?
You can view the jitted assembly with the Visual Studio Debugger (Debug -> Windows -> Disassembly).
If you start the program with the debugger already attached (F5 in Visual Studio) then you'll see the non-optimised version of the assembly that's generated when the jitter detects such a situation.
If you need the optimised, non-debug version of the jitted assembly then you'll need to compile your program in Release mode and start it without the debugger attached (Ctrl+F5 in Visual Studio). Then attach the debugger to the running process once you know that the required section of code has already been jitted. Then you can break and view the jitted assembly.
.NET uses a just-in-time compiler. The machine code isn't generated until the last possible moment, just before a method starts executing. That makes it pretty difficult to 'capture the ASM'.
If you are just interested in what it looks like then right-click the source code window while debugging and select "Goto Disassembly". You are not looking at the 'real' machine code until you debug the Release build and re-enable the JIT compiler optimizer with Tools + Options, Debugger, General.
Another option is to run ngen.exe, the 'pre-compiler' for .NET. A foo.dll assembly will produce a foo.ni.dll assembly in the c:\windows\assembly or c:\windows\microsoft.net\assembly directory. This .ni.dll image file contains the jitted machine code.
精彩评论