开发者

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 shou开发者_如何学运维ld, but if i run the .exe, it still prints "debug". What do i have to do to get this to work right?


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.


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


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

How do I get the #if DEBUG to work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜