Build Configurations

The .NET Framework provides two classes in the System.Diagnostics namespace, Debug and Trace, which help debug your application. These classes, mentioned in Section 22.2.4.2 and described in Chapter 21, enable several debugging techniques, such as assertions, conditional error messages, and capturing errors to a log file. The Debug and Trace classes have identical methods and properties.

To use tracing or debugging, you must compile the application with the appropriate flag. To include Debug statements in a C# program, include /d:DEBUG in the compile command line or add #define DEBUG as the first line in the source code file. To include Trace statements in a C# program, include /d:TRACE in the compile command line or add #define TRACE as the first line in the source code file.

To include Debug statements in a VB.NET program, include /d:DEBUG=True in the compile command line. To include Trace statements in a VB.NET program, include /d:TRACE=True in the compile command line.

Tip

The /d command-line compile switch is the short form of /define, used to define conditional compilation symbols.

In Visual Studio .NET, these flags are set by default by the Configuration Manager, described shortly. They can also be set explicitly. In C#, this is done by right-clicking on the project in the Solution Explorer and viewing the Property Pages dialog box for the project (not to be confused with the Properties window), and then going to the Configuration Properties Build page. ...

Get Programming .NET Windows Applications 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.