VB 2010 Express:Debug.WriteLine 在调试版本中完全优化?
似乎没有涵盖的简单问题:如果我在代码中使用大量 Debug.WriteLine
语句,它们在我的生产版本中会完全不存在吗?
我的意思是:编译器是否足够聪明,不会为这些调用发出任何代码?或者我是否必须用 #if DEBUG..#end
if 指令包围它们?
Simple question that does not seem to be covered: If I use a lot of Debug.WriteLine
statements in my code, will they be completely absent in my production version?
I mean: Is the compiler smart enough to not emit any code for those calls? Or would I have to surround them by #if DEBUG..#end
if directives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调试类成员用 ConditionalAttribute 标记,因此如果在发布模式下完成构建,则不会编译调用站点
请参阅本页顶部
http://msdn.microsoft.com/en-us/library/9z9k5ydz.aspx
Debug class members are marked with ConditionalAttribute thus call sites won't be compiled if the build is done in Release mode
See the top of this page
http://msdn.microsoft.com/en-us/library/9z9k5ydz.aspx
调试类输出仅在调试配置中有效。 Trace 类在调试和发布中均有效。因此,您不需要使用#if DEBUG。
Debug class output works only in Debug configuration. Trace class works both in Debug and Release. So, you don't need to use #if DEBUG.
如果您在 RELEASE 模式下构建项目,则所有 Debug.WriteLine 语句被省略,因为它们用 ConditionalAttribute 设置为 DEBUG。
这是在编译时完成的。当您使用反编译器(例如 .NET Reflector、dotNetPeek)分析程序集时,您可以检查这一点。如果您在 DEBUG 模式下构建,则会出现对 Debug.WriteLine 的调用。如果您在 RELEASE 模式下构建它,则不会出现调用。
If you build your project in RELEASE mode all the Debug.WriteLine statements are omitted cause they are decorated with the ConditionalAttribute set to DEBUG.
This is done at compile time. You can check this when you analyze your assemblies with a decompiler (such as .NET Reflector, dotNetPeek). If you build in DEBUG mode the calls to Debug.WriteLine are present. If you build it in RELEASE mode the calls are not present.