For one reason or another, I sometimes find it useful or just interesting to look at the optimised compiler output for a function.
For unmanaged C/C++ code, my favourite way to do this has been to compile in Release mode, stick a breakpoint in the function of interest, run, and view the disassembly in Visual Studio when it hits the breakpoint.
I recently tried this with a C# project and discovered that that technique doesn’t work. Even in Release mode, the disassembly I see is obviously not optimised. I found and disabled (in Visual Studio 2010) the “Debug … Options and Settings … Debugging … General … Suppress JIT optimization on module load” option, which presumeably gets me closer to what I want, only now it warns me when I try to run it, and I then can’t get it to stop on a breakpoint so that I can see the disassembly.
So, if I want to see the disassembled, optimised output of the CLR (4.0) jitter for a function, what’s the best way to go about that? To be clear, I’d like to see the x86 (or preferably x86_64) disassembly, not just the IL disassembly (which you can see in Reflector).
Of course, after half a day of searching for the answer on this one, I find the answer myself 5 minutes after I ask on SO.
I was close; the only missing step from what I had in the question was that "Enable Just My Code" must also be unchecked in the options.
The full guide is available here: <Link>