有没有办法判断一个C#程序集已编制与优化参数? [英] Is there a way to tell if a C# assembly has been compiled with the optimization parameter?
问题描述
相反,是有办法知道它是编译时启用或禁用的优化参数。我不想知道,如果它的发布或调试,因为无论是可以使用或不优化启用。从我的角度来看,即使代码表示,它的发行版,它是真正的优化?谢谢你。
要检查的方法之一是看 DebuggableAttribute
在组件( DOC )。如果C#编译器传递的/优化选项的 DisableOptimizations
标志将不会被设置。
请注意:尽管这会为大多数情况下,这是不是100%傻瓜证明解决办法。它可以被打破它至少通过以下方式
<醇>
中的
DebuggableAttribute
它将优先Rather, is there a way to tell if it's been compiled with the optimization parameter enabled or disabled. I don't want to know if it's release or debug, since either can be enabled with or without optimizations. From my perspective, even though the code says it's release version, is it truly optimized? Thanks.
One way to check is to look at the DebuggableAttribute
(doc) on the assembly. The DisableOptimizations
flag will not be set if the C# complier was passed the /optimize option.
Note: Although this will work for the majority of scenarios this is not a 100% fool proof solution. It can be broken it at least the following ways
- Compiling with another language that has different semantics for optimization
- If the user hand defines the
DebuggableAttribute
it will take precedence over what the C# compiler defines
这篇关于有没有办法判断一个C#程序集已编制与优化参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!