tags:

views:

581

answers:

4

how can i disable compiler optimization in c#??

A: 

In Visual Studio I believe you can just create a debug build, but it includes additional debug information. Project Properties (right click on project in solution) gives you access to the controls governing compilation.

If you build on the command line with csc.exe see the /optimize parameter docs. If you don't specify /optimize then the assembly should not be optimized.

BrianLy
+1  A: 

At the command line (csc), /optimize-

In the IDE, project properties -> build -> "optimize code"

For some JIT optimizations, you can use [MethodImpl(...)]

Marc Gravell
If you don't specify /optimize you get the same behaviour as /optimize-
BrianLy
specifically use [MethodImpl(MethodImplOptions.NoOptimization)] on methods that you want to skip optimization for. Use case: in certain scenarios, where a native call calls another native call, the compiler will generate invalid IL code, and the runtime will throw a InvalidProgramException when you try to run it. You can either turn off optimization for the whole program, or selectively use [MethodImpl(MethodImplOptions.NoOptimization)] on the methods that are using the native calls. I had to do exactly this to resolve that problem in a recent application I was working on...
Troy Howard
+1  A: 

Project->Properties In Build tab there's a "Optimize code" checkbox.

Jaime Pardos
A: 
Chris S