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.
|
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
The Configuration Manager in Visual Studio .NET provides an easy way to control the build process. By default, the Configuration Manager contains two different configurations: Debug and Release. You can quickly select between the two using the Configuration Manager drop-down menu shown in Figure 22-11.
Figure 22-11. Configuration Manager drop-down menu
The main difference between the two configurations is that Debug statements are included only in compiled Debug builds, not Release builds, while Trace statements are included in both. All the differences between Debug and Release builds are listed in Table 22-3.
Debug |
Release |
---|---|
Debug and Trace statements included in compiled build. |
Only Trace statements included in compiled build. |
Not optimized for speed. |
Optimized for speed. |
Enables incremental build. |
Disables incremental build. |
C# output goes into binDebug directory. |
C# output goes into binRelease directory. |
VB.NET output goes into bin directory. |
VB.NET output goes into bin directory. |
Breakpoints enabled. |
Breakpoints disabled. |
Notice that in C# projects, Debug and Release builds go into separate bin directories, while in VB.NET, both go into the same bin directory. You can change the output path in either language for any specific configuration by right-clicking on the project in the Solution Explorer and selecting Properties. This opens the Property Pages dialog box, shown in Figure 22-12 for C#. The VB.NET version of the dialog box is formatted somewhat differently but is functionally the same. Any changes made to a configuration apply only to this project.
Figure 22-12. Project Property pages dialog box for C#
|
You can specify which projects within a solution will be built for any specific configuration by opening the Configuration Manager dialog box, shown in Figure 22-13. This dialog box can be accessed from the configuration drop-down menu shown in Figure 22-11, from the Property Pages dialog box shown in Figure 22-12, or from the Build menu.
Figure 22-13. Configuration Manager
The Active Solution Configuration drop-down menu lets you select the active configuration and create new configurations or edit existing configurations. You can control which projects get built for each configuration by checking or unchecking the boxes in the Build column.
|