Building Projects

Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Chapter 1.  Using the Unified Visual Studio IDE

Building Projects

There are several kinds of builds that you will want to make. When you are testing new code just added, verifying that refactoring didn't break anything, or if your code is being tested internally, you will want to perform a debug build.

Note

Refactoring is a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior (Fowler, 2000).


When your code has been tested according to the application's needs and the qualitative standards determinedwhich should include unit, integration, and black-box testing and can include white-box testing and a thorough quality assurance reviewyou will want to perform a release build. Black-box testing refers to testing from the user 's perspective without knowledge of the algorithms and types that describe how the solution was implemented. White-box testing refers to testing by stepping over the individual lines of code with knowledge of the algorithms and types. For a detailed discourse on testing, refer to the book Software Testing by Ron Patton from Sams.

Visual Studio .NET allows you to configure and manage options for debug, release, or custom builds.

Using the Configuration Manager

The Configuration Manager dialog box displays the active solution configuration and the project contexts for each project in your solution. (When you read "solution," think Visual Basic Group , or .VBG.) Open the Configuration Manager by choosing Build, Configuration Manager. To add a new solution configuration, select <New> from the Active Solution Configuration drop-down list. To change the name of or delete an existing solution configuration, select <Edit>.

The Project Contexts grid displays the list of configuration information for each project in your solution. The Project column contains the project name. The Configuration column displays the currently selected desired build configuration, and the Platform column indicates the platform for which the build is targeted . The Build column indicates whether the project will be compiled. A final Deploy column will be displayed for projects that are deployable . The Deploy column indicates whether a project will be deployed when the Run or Deploy command is invoked.

Common Properties

Project configuration settings can be viewed and modified by selecting the project from the Solution Explorer and choosing Project, Properties. The Common Properties folder in the property pages contains configuration information common to all configurations.

General Property Defaults

The General properties define the assembly name, the type of the target application, startup module, and the Root Namespace, as well as static text indicating the project folder, project filename, and target application name.

Compiler Defaults

Select the Build view from Common Properties, and you will see that Option Explicit is On and Option Strict is Off and Option Compare is set to Binary. In the Build view, you can select the project icon too. Change Option Strict to On. I will elaborate in a moment why this is the preferred setting.

As a refresher, Option Explicit On means that you must declare variables before using them. Option Strict On precludes late binding, which is demonstrated by assigning a specific type to a general type and invoking a method of the specific type. Option Strict On requires you to perform a specific type cast. Option Strict On also enforces narrowing type conversions where only implicit conversions of smaller types to larger types are allowed. See Listing 1.3 from the OptionStrict.vbproj example.

Listing 1.3 Demonstrating an implication of the compiler setting Option Strict On
 Sub Main() Dim AnInt As Integer = 5 Dim ALong As Long = 7 ALong = AnInt ' causes compiler error when Option Strict On AnInt = ALong MsgBox(AnInt) End Sub 

In Listing 1.3, if Option Strict is On, AnInt = ALong causes a compiler error. If you assign a long to an integer, there is a possibility that information will be lost due to squeezing a 64-bit long into a 32-bit integer. However, the reverse isn't true; converting an integer to a long is okay. Thirty-two-bit integers fit nicely into 64-bit longs. If Option Strict is Off, the compiler will allow you to perform widening implicit type conversions.

The default comparison option is a case-sensitive compare, or Option Compare Binary.

Imports Property Defaults

The Imports statement allows you to import and remove namespaces, and the Import section of the project's Common Properties folder contains a list of the namespaces that are already imported. (A namespace consists of a logical grouping of types. Elements in the same namespace are found in the same assembly.)

Reference Path Properties

The References properties are used to define a list of folders that will be searched to resolve references in your application.

Designer Defaults

The Designer Properties page provides configuration information for the layout of the Web designer, the target browser schema, and Web scripting languages.

The Page Layout property indicates whether controls should be laid out linearly or using a two-dimensional grid layout. Target schema enables you to indicate what version and brand of Web browser your application is targeting, and client script language allows you to select VBScript or JScript as the default language for scripting.

Configuration Properties

The Configuration Properties folder contains pages for managing Debugging, Optimizations, Build, and Deployment options.

The Debugging page allows you to specify a Start Action and Start Options. A Start Action might be to load an external program. For example, you need to load a host application for a DLL. When you are creating an add-in, the Start external program would be VS .NET itself. Start Options provide fields for specifying a working directory and command-line arguments. (Refer to the section "Retrieving Command-Line Arguments" in Chapter 13 for more information on console applications and command-line arguments.)

The Optimizations page contains a few basic compiler optimization settings. The Build page allows you to specify an output path, generate debugger information, and define application constants. The Configuration page provides quick access to the Configuration Manager and enables you to specify the current configuration.

Debug Build

The default recommended configuration options are selected for a Debug build. As with Visual Basic 6, you can specify command-line arguments, specify a working directory, remove integer overflow checks, enable optimizations, tell the compiler to treat warnings as errors, specify an output path, and define compiler constants.

When you open the property pages and select the Configuration Properties folder, you are modifying values that will be saved to the configuration selected in the top left corner of the Configuration Properties view. By default the Debug configuration writes the application to the \ bin folder, generates debug information, enables build warnings, and defines the constants DEBUG and TRACE. All these options are set for the Build view of the default Debug configuration.

I prefer not to compile or ship code with warnings, so I indicate that compiler warnings should be treated as errors.

Release Build

A release build is the build you are going to ship to your customers. The release build is similar to the debug build but doesn't generate debug information, nor does it define the DEBUG constant.

For the release build, you may be able to tolerate a slower compile for a more optimized application. To use the optimizing compiler, select Enable Optimizations in the Optimizations page of the Configuration properties pages.

Command-Line Builds and Make Files

Some development shops prefer to perform command-line builds, or more likely, use makefiles to automate the build process, and for good reason. A makefile allows you to automate checking out files by label, perform precise compilations on any complexity of source and target applications, and run automated scripts to build installation disks. (There are other things that you can do as well.)

If you need to perform a command-line build, here is an example.

[View full width]
 
[View full width]
"C:\ Progam Files\ Microsoft Visual Studio .Net\ Common7\ IDE\ devenv" OptionStrict.sln / graphics/ccc.gif runexit

The preceding command will build the OptionStrict.sln solution and run the executable. The /runexit instructs devenv.exe to run the program and exit. Notice that you are running Visual Studio (devenv.exe) to perform the build.


Team-Fly    
Top
 


Visual BasicR. NET Unleashed
Visual BasicR. NET Unleashed
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 222

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net