开发者

VB 2010 Express: Debug.WriteLine optimized away completely in debug version?

开发者 https://www.devze.com 2023-03-31 18:18 出处:网络
Simple question that does not seem to be covered: If I use a lot of Debug.WriteLine statements in my c开发者_JS百科ode, will they be completely absent in my production version?

Simple question that does not seem to be covered: If I use a lot of Debug.WriteLine statements in my c开发者_JS百科ode, 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?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消