469,362 Members | 2,441 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

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

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.
Nov 21 '05 #1
4 21172
"Henry Padilla" <pa******@hotmail.com> schrieb:
[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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
"Henry Padilla" <pa******@hotmail.com> schrieb:
[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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
I found the problem, I needed to declare the DTE object. Like so:

Dim DTE as EnvDTE.DTE
DTE =
System.Runtime.InteropServices.Marshal.GetActiveOb ject("VisualStudio.DTE")
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:bA****************@newssvr19.news.prodigy.com ...

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.
Nov 21 '05 #4
"Henry Padilla" <pa******@hotmail.com> schrieb:
[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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by xTroLL | last post: by
7 posts views Thread by Srinivasa Rao | last post: by
reply views Thread by =?Utf-8?B?SmVmLnB0Yw==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.