views:

35

answers:

3

I'm using VB Express 2008. I know how to tell if code was built in debug more or release, but now I would like know how to tell if it is running in the Visual Studio IDE or not (so that I can add some debug MsgBox() and not worry about them showing if I ever accidentally ship a debug version).

A: 

If you're building for Test and Prod, consider using a preprocessor directive in your code.

#If DEBUG Then
    MsgBox("Foo")
#End If

This falls down, of course, if you ship a debug-built binary to a non-dev environment. I understand this is attacking the problem from another angle from where you asked the question (the IDE).

p.campbell
+1  A: 

Is System.Diagnostics.Debugger.IsAttached what you're looking for?

Guy
+1  A: 

Try checking the IsAttached property of System.Diagnostics.Debugger

Jorgen Thelin
sorry, but @guy beat to to it by one minute (+1, though)
LeonixSolutions