Main Site Documentation

Debug/Release


#1

This may sound a strange question, as I am very familiar with the normal difference between these two selections in say C++, but does it actually make any difference with .NET MF?

In project options, there are potentially ‘optimize code’ check boxes that one could select in a Release build, but as the whole thing is interpreted, is there any difference in choosing one over the other before doing a true release?

Thanks!


#2

I have tried both before but never seen a significant difference. Note this is not NETMF option, it is simply the C# compiler.


#3

In theory it should also automatically strip out your debug statements when going to release. This ticket has already been submitted to Microsoft…

Also, one difference I have noticed in some projects is that they will not run in debug mode unless connected to the debugger. What I mean is that if I run a debug version and it gets deployed to the device and then I unplug USB and reboot the device, the code doesn’t seem to exist anymore. If I then swap to release and do the same thing then it works. Could be something weird I’m doing in my code. I haven’t spent much time researching it since I discovered the workaround.


#4

Are there any issues leaving debug (e.g. debug.print) statements in? Will the platform dispose of the output or try and buffer it awaiting a debugger?

On other platforms it doesn’t affect things, but just wondering…


#5

For NETMF, Visual Studio doesn’t automatically non-compile the debug statements. You’ll find several threads about it here. They won’t cause the program to pause but they do effect program performance and size. The usual recommendation is to surround Debug functions as…

#if DEBUG
Debug.Print(“This is insane…”);
#endif


#6

There is also an option to give a method the conditional attribute. The method itself and calls to this method will only compile into code if the conditional is true.



using System.Diagnostics;   // used for conditional attribute

public class program
{
    [Conditional("DEBUG")]
    static void DebugPrint(string msg)
    {
        Debug.Print(msg);
    }

    public static void Main()
    { 
        DebugPrint("This call and text will only exist in code/memory in DEBUG mode");
    }    
}



#7

If that works why didnt Microsoft include that on debug libraries ?


#8

I’m not sure about your question.


#9

I like the use of the conditional attribute as that produces cleaner code.

Thanks!