Debug/Release

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!

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

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.

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…

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

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");
    }    
}


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

I’m not sure about your question.

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

Thanks!