broke
broke

Reputation: 8302

How do I get the #if DEBUG to work?

I have a simple application:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

#If DEBUG Then
lblDebug.Text = "Debug"
#Else
    lblDebug.Text = "Not in debug"
#End If

Now when I run it in VS, it prints "debug" like it should, but if i run the .exe, it still prints "debug". What do i have to do to get this to work right?

Upvotes: 0

Views: 121

Answers (3)

VoodooChild
VoodooChild

Reputation: 9784

Change your "Solution Configuration" to Release and build it again.

alt text

Upvotes: 3

Adam Maras
Adam Maras

Reputation: 26853

It's already working "right." The way to make it work the way you think it should is to change your Build Configuration from Debug to Release. Then, when you run it in Visual Studio (or from the executable file) it will say "Not in debug" the way you expect.

Now, if you're more interested in checking at runtime to see if there's a debugger attached to the application, you can use Debugger.IsAttached to see if the program is currently being debugged.

Upvotes: 7

AndrewC
AndrewC

Reputation: 6730

Build the exe in Release mode (select it from the dropdown at the top of Visual Studio).

Upvotes: 4

Related Questions