How can I determine if the app is running in Debug mode or Release mode?

  • Thread starter Thread starter Henry Padilla
  • Start date Start date
H

Henry Padilla

I found the following code snippet in the help but it doesn't seem to
compile.

Dim debugger As EnvDTE.Debugger
Dim IsDebugging As Boolean

debugger = DTE.Debugger

If (debugger Is Nothing) Then
MsgBox("Debugger doesn't exist! Fatal error.")
IsDebugging = False
Else
IsDebugging = (debugger.CurrentMode <>
dbgDebugMode.dbgDesignMode)
End If

I'm getting an error on "DTE.Debugger" saying "Reference to a non-shared
member requires an object reference."

So what did Microsoft leave out? Is there a different way to do this that's
better?
Thanks in advance for the help.

Tom P.
 
Henry Padilla said:
[How can I determine if the app is running in Debug mode or Release mode?]

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

Make sure that the option "Configuration settings" -> "Build" "Define DEBUG
constant" in the project properties is checked.

- and/or -

You can check if a debugger is attached:
'System.Diagnostics.Debugger.IsAttached'.
 
Herfried K. Wagner said:
Henry Padilla said:
[How can I determine if the app is running in Debug mode or Release
mode?]

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

That's C# not VB. In VB this gets confused with the Debug() object.

Make sure that the option "Configuration settings" -> "Build" "Define
DEBUG constant" in the project properties is checked.

- and/or -

You can check if a debugger is attached:
'System.Diagnostics.Debugger.IsAttached'.

This I might try. Thanks!

Tom P.

 
I found the problem, I needed to declare the DTE object. Like so:

Dim DTE as EnvDTE.DTE
DTE =
System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")


Henry Padilla said:
Dim debugger As EnvDTE.Debugger
Dim IsDebugging As Boolean

debugger = DTE.Debugger

If (debugger Is Nothing) Then
MsgBox("Debugger doesn't exist! Fatal error.")
IsDebugging = False
Else
IsDebugging = (debugger.CurrentMode <>
dbgDebugMode.dbgDesignMode)
End If


Tom P.
 
Henry Padilla said:
[How can I determine if the app is running in Debug mode or Release
mode?]

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

That's C# not VB. In VB this gets confused with the Debug() object.

The code above should work in VB.NET.
 
Back
Top