Freigeben über


Conditional Compilation Overview

Conditional compilation is the inclusion or exclusion of certain blocks of code depending on the project settings. For example, you would not want an extension that creates a log file every time it is loaded in the final version of the extension because it is slow and wastes system resources. Use conditional compilation to eliminate unnecessary code when the release version of the extension is built.

By default, Microsoft Visual Studio 2008 defines the DEBUG preprocessor directive in the debug configuration of a project and excludes the DEBUG directive in the release configuration of the project. This directive is very useful in excluding code that you use specifically for debugging when you build the release version of the extension.

Use the DEBUG directive by adding code similar to the following:

#if(DEBUG)
    System.Diagnostics.Debug.WriteLine("debug output");
#endif
#If Debug Then
    System.Diagnostics.Debug.WriteLine("debug output")
#End If

The code between the #If and #End If is included only if the DEBUG directive is present.

See Also

Concepts

Testing and Debugging Rules Extensions
Creating Rules Extensions
Rules Extensions Examples