有没有办法判断一个C#程序集已编制与优化参数? [英] Is there a way to tell if a C# assembly has been compiled with the optimization parameter?

查看:301
本文介绍了有没有办法判断一个C#程序集已编制与优化参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相反,是有办法知道它是编译时启用或禁用的优化参数。我不想知道,如果它的发布或调试,因为无论是可以使用或不优化启用。从我的角度来看,即使代码表示,它的发行版,它是真正的优化?谢谢你。


解决方案

要检查的方法之一是看 DebuggableAttribute 在组件( DOC )。如果C#编译器传递的/优化选项的 DisableOptimizations 标志将不会被设置。



请注意:尽管这会为大多数情况下,这是不是100%傻瓜证明解决办法。它可以被打破它至少通过以下方式



<醇>
  • 使用具有优化不同的语义另一种语言编译

  • 如果用户手中定义了什么C#编译器定义


  • 中的 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

    1. Compiling with another language that has different semantics for optimization
    2. If the user hand defines the DebuggableAttribute it will take precedence over what the C# compiler defines

    这篇关于有没有办法判断一个C#程序集已编制与优化参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆