1.8. Include Code Selectively at Build Time

Problem

You need to selectively include and exclude sections of source code from your compiled assembly.

Solution

Use the #If, #ElseIf, #Else, and #End If preprocessor directives to identify blocks of code that should be conditionally included in your compiled assembly. Use the System.Diagnostics.ConditionalAttribute attribute to define methods that should be called conditionally only. Control the inclusion of the conditional code using the #Const directive in your code, or use the /define switch when you run the VB .NET compiler from the command line.

How It Works

If you need your application to function differently depending on factors such as the platform or environment on which it runs, you can ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.