如何在 C# 中禁用编译器优化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1199204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I disable compiler optimization in C#?
提问by
How can I disable compiler optimization in C#?
如何在 C# 中禁用编译器优化?
回答by Brian Lyttle
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.
在 Visual Studio 中,我相信您可以只创建一个调试版本,但它包含其他调试信息。项目属性(右键单击解决方案中的项目)可让您访问控制编译的控件。
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.
如果您使用 csc.exe 在命令行上构建,请参阅/optimize 参数文档。如果不指定 /optimize,则不应优化程序集。
回答by Marc Gravell
At the command line (csc), /optimize-
在命令行 (csc) 中, /optimize-
In the IDE, project properties → build → "optimize code"
在IDE中,项目属性→构建→“优化代码”
For someJIT optimizations, you can use [MethodImpl(...)]
对于一些JIT 优化,您可以使用[MethodImpl(...)]
回答by Ignacio Soler Garcia
You can disable the optimizations in runtime using an .ini file: http://msdn.microsoft.com/en-us/library/9dd8z24x.aspx
您可以使用 .ini 文件在运行时禁用优化:http: //msdn.microsoft.com/en-us/library/9dd8z24x.aspx
Enter the following text into you .ini [for example Explorer.ini]
将以下文本输入您的 .ini [例如 Explorer.ini]
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0
回答by silver
before you start to change the settings of the project which might find its way to production verify that your solution configuration is set for Debug and not Release.
在开始更改可能会进入生产环境的项目设置之前,请确认您的解决方案配置设置为 Debug 而不是 Release。
I had the same issue and then I saw that it was set to Release by mistake...
我遇到了同样的问题,然后我看到它被错误地设置为 Release ......