none
Difference between debug and release in .net

    Question

  • What is difference between debug and release? When I am compiling in debug mode, then how compiler knows it is debug mode or release mode. How compiler map break point in code line ( debug mode).

    Wednesday, April 11, 2007 10:00 AM

Answers

  • It is not well documented, here's what I know.  The compiler emits an instance of the System.Diagnostics.DebuggableAttribute.  In the debug version, the IsJitOptimizerEnabled property is True, in the release version it is False.  You can see this attribute in the assembly manifest with ildasm.exe

    The JIT compiler uses this attribute to disable optimizations that would make debugging difficult.  The ones that move code around like loop-invariant hoisting.  In selected cases, this can make a big difference in performance.  Not usually though.

    Mapping breakpoints to execution addresses is the job of the debugger.  It uses the .pdb file and info generated by the JIT compiler that provides the IL instruction to code address mapping.  If you would write your own debugger, you'd use ICorDebugCode::GetILToNativeMapping().
    Wednesday, April 11, 2007 12:30 PM
    Moderator
  • Debug and Release are different configurations for building your project. 

    You generally use the Debug mode for debugging your project, and the Release mode for the final build for end users.

    The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.

    The Release mode enables optimizations and generates less (or no) extra debug data.


    You can append the following code to the AssemblyInfo.cs file:
    #if DEBUG
    [assembly: AssemblyDescription("Debug")]
    #else
    [assembly: AssemblyDescription("Release")]
    #endif

    After compiled to Assembly file (.dll or .exe), right-click the file and check its version property:  Comments item is Dubug or Release.
    Wednesday, April 11, 2007 12:29 PM

All replies

  • AFAIK debug and release executables (dll's, exe's, etc) are idenical to one another (unless you have #if DEBUG compiler directives in your code).
    The big difference is that a debug compile generates .pdb files containing debugging information.
    Wednesday, April 11, 2007 10:33 AM
  • There are also some other tiny differences between a Debug .Net Dll and a Release .Net Dll.

     

    If you compile in debug (/debug+), the Debuggable attribute is added to the assembly.

     

    To see the difference: use Il Dasm.exe=>Open=>Ctrl-M (View->MetaInfo->Show)=> section Assembly, in Debug a CustomAttribute of type System.Diagnostics.DebuggableAttribute is added. At run time, you can use GetCustomAttributes on your assembly.

     

    Note: it is a good practice to keep the release and debug code similar, and not to have different behaviour, except extra (and slow) assertion.


    Regards

    Wednesday, April 11, 2007 11:48 AM
  • Debug and Release are different configurations for building your project. 

    You generally use the Debug mode for debugging your project, and the Release mode for the final build for end users.

    The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.

    The Release mode enables optimizations and generates less (or no) extra debug data.


    You can append the following code to the AssemblyInfo.cs file:
    #if DEBUG
    [assembly: AssemblyDescription("Debug")]
    #else
    [assembly: AssemblyDescription("Release")]
    #endif

    After compiled to Assembly file (.dll or .exe), right-click the file and check its version property:  Comments item is Dubug or Release.
    Wednesday, April 11, 2007 12:29 PM
  • It is not well documented, here's what I know.  The compiler emits an instance of the System.Diagnostics.DebuggableAttribute.  In the debug version, the IsJitOptimizerEnabled property is True, in the release version it is False.  You can see this attribute in the assembly manifest with ildasm.exe

    The JIT compiler uses this attribute to disable optimizations that would make debugging difficult.  The ones that move code around like loop-invariant hoisting.  In selected cases, this can make a big difference in performance.  Not usually though.

    Mapping breakpoints to execution addresses is the job of the debugger.  It uses the .pdb file and info generated by the JIT compiler that provides the IL instruction to code address mapping.  If you would write your own debugger, you'd use ICorDebugCode::GetILToNativeMapping().
    Wednesday, April 11, 2007 12:30 PM
    Moderator
  • hi, i am new in this thing, and i have done a small windows forms programs and i use the default configuration to build in debug mode and now i am trying to run this program in another machine this doesn't run can anyone of you help me to solve this problem, please i am stuck in this two weeks ago ...... please
    Tuesday, May 15, 2007 9:39 AM
  • In debug mode, many of the compiler optimizations are turned off which allow the generated executable match up with the code. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. Debugging information is also generated help the debugger figure out where it is in the source code.

    In release mode, most of the compiler's optimizations are turned on. Chunks of your code could be completely deleted, removed, or rewritten. The resulting executable will most likely not match up with your written code. However, normally release mode will run faster then debug mode due to the optimizations.

    • Proposed as answer by queersane Monday, December 20, 2010 5:40 AM
    Wednesday, July 29, 2009 12:38 PM
  • What about:

     

     Public Sub getAssemblyMode()

            If (Debugger.IsAttached) Then

                sDebugMode = "Debug" '
                bBreakOnError = True
            Else

                sDebugMode = "Release"
                bBreakOnError = False

            End If

     End Sub

     

    Does it do the same thing?

    Francois

    Wednesday, May 04, 2011 2:33 AM
  • Debug and Release are different configurations for building your project. 

    You generally use the Debug mode for debugging your project, and the Release mode for the final build for end users.

    The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.

    The Release mode enables optimizations and generates less (or no) extra debug data.


    You can append the following code to the AssemblyInfo.cs file:
    #if DEBUG
    [assembly: AssemblyDescription("Debug")]
    #else
    [assembly: AssemblyDescription("Release")]
    #endif

    After compiled to Assembly file (.dll or .exe), right-click the file and check its version property:  Comments item is Dubug or Release.

    Thank you MR Obvious

    The biggest difference is performance

    In a debug dll several extra instructions are added to enable you to set a breakpoint on every source code line in for example Visual Studio. Also the code will not be optimized, again to enable you to debug the code.

    In the release version these extra instructions are removed and several extra optimizations are done by the compiler. Try for example debugging a release compiled assembly in visual studio, you will notice that you are not allowed to set a breakpoint on each and every line.

    Monday, November 04, 2013 11:33 PM