Saturday, May 21, 2016

Conditional Compilation

Today I learn  that I can do Conditional Compiling on VB.Net,

In conditional compilation, particular blocks of code in a program are compiled selectively while others are ignored.

Reference: Conditional Compilation in Visual Basic

For example if I Write this code in the form Load event:
    Private Sub frmStarter_Load(sender As Object, e As EventArgsHandles Me.Load

#If DEBUG Then
        MsgBox("This is DEBUG build")
#Else
        MsgBox("This is not a DEBUG build")
#End If
    End Sub
When I build in DEBUG mode, the "MsgBox("This is DEBUG build")" and when I build in RELEASE mode or any other custom mode, the "MsgBox("This is not a DEBUG build")" will be triggered.

This is really handy.

No comments:

Post a Comment