Chapter 3: Visual Studio 2005 Integrated Development Environment


Microsoft Corporation

March 2006

Summary: The Visual Studio 2005 integrated development environment includes a number of new and improved productivity features. The IDE has also been redesigned with a view toward providing developers with more direct access to the .NET Framework components, such as the new settings and resource architecture. (28 printed pages)


Application: IDE Enhancements
Help and Community Integration
Project Enhancements
Managing Assembly Information
Resources and Framework Integration
New and Improved Tool Windows
Writing Correct Code
Debugger Enhancements


Before .NET, there was Microsoft Visual Basic 6, one of the most popular and easy-to-use programming languages of all time. The simple reason for its success was that it allowed developers to be more productive than their counterparts working with other programming languages and development tools. Certainly the productivity benefits enjoyed by Visual Basic 6 developers came at the expense of limited language features. When Visual Basic .NET came along, it introduced a new programming architecture and features, such as full access to the platform, for building state-of-the-art applications. Visual Basic .NET was thus established as a first-class programming language. However, the promise of all that functionality and language support came at the expense of some productivity benefits Visual Basic developers had come to love and expect.

Microsoft Visual Studio 2005 contains a number of new enhancements, innovations, and advances to the development environment, offered with the singular objective of making Visual Basic .NET developers more productive than ever before. This chapter explores some of these features, and explains how you can make use of them as a developer to write code faster and more accurately.

**Tip   **Among other "improvements" to the IDE, Visual Studio 2005 reintroduces Edit and Continue, which is good news for experienced Visual Basic developers.

Application: IDE Enhancements

This application demonstrates the Class Designer in the Visual Studio 2005 IDE, a tool for visually designing the class hierarchy in a Visual Basic .NET application. Before examining the details of the application, let’s first take a more general look at features that are either new or improved in the Visual Studio 2005 IDE.

Configuration Settings

If you have used previous versions of Visual Studio, you have probably spent some time customizing the development environment. You might have learned through some experimentation that you can specify the position of tool windows, or you might have found that menus and toolbars in Visual Studio are fully customizable. You can also configure keyboard mappings, project template types, Help filters, and so on. In fact, Visual Studio has always been designed for you to arrange elements of the IDE to best suit your individual development style.

The Options Dialog

The Options dialog shown in Figure 3-1 provides a broad array of settings categories for customizing the Visual Studio development environment. By default, the Options dialog displays the most common settings. To display all of the available settings, select the Show All Settings check box.


Figure 3-1. The Options dialog box

Before the release of Visual Studio 2005, the main drawback with IDE customization was that you had no way to save your preferences in a portable format, which would come in handy if you had to re-create those settings on another machine. With Visual Studio 2005, you can now quickly and easily restore your personal settings at a later time or on another machine. Visual Studio 2005 allows you to use customized settings in the following ways:

  • Make a copy of your current settings for use on a second machine.
  • Distribute your settings to other developers.
  • Allow teams to use the same settings for certain elements of the IDE (such as the code editor, for example), while preserving individual customizations in other areas of the IDE.

As shown in Figure 3-2, the Options dialog Environment settings include an Import/Export Settings item. The file specified in the Always Save My Settings To This File text box is updated every time you close Visual Studio. This can be a local file or a network file. In a scenario where you regularly work on two machines, set this file to a network location accessible by both machines; this will ensure that you enjoy the same Visual Studio "look and feel" on both machines. In addition, every time you change a setting on one machine, it will automatically show up on the other machine.


Figure 3-2. Import/Export Settings options

Under the Team Settings section, you can specify a .vssettings file containing settings to be shared among a team of developers. To understand how this would be useful, consider a situation in which a development team’s members must all use the same indenting and formatting options for Visual Basic .NET code files. The lead developer can configure the formatting options in Visual Studio 2005, and then use the Import/Export Settings dialog to save only those formatting settings to a .vssettings file on a network share. Other members of the development team would then update their Visual Studio configuration to use that team settings file. If the team later decides to change the defaults, the lead developer can export new settings to that same file location and everyone on the team will automatically receive the new settings the next time they launch Visual Studio.

Note   Your active settings consist of two parts: predefined customizations from the installed .vssettings file you selected the first time you started Visual Studio 2005, and any subsequent IDE customizations you have made. Active settings are saved automatically to the currentsettings.vssettings file every time you exit Visual Studio.

The Import/Export Settings Dialog

The Visual Studio 2005 Tools menu includes an Import/Export Settings menu item that opens a dialog box for managing settings files. The dialog provides three basic areas of functionality:

  • Exporting your current IDE settings to a file
  • Importing IDE settings from a file
  • Resetting your environment to a work style predefined in a default file

Depending on whether you are exporting or importing settings, the dialog lets you choose which settings to export to a .vssettings file, or which settings to import from an existing .vssettings file, respectively.

Note   A settings category generally defines a logical grouping of settings for a tool window, an options page, or an IDE feature.

Figure 3-3 shows the Import/Export Settings dialog box, which is accessed from the Tools | Import and Export Settings menu. Once Export is selected, you can choose which specific settings, and groups of settings, to export.


Figure 3-3. Export IDE settings

An obvious downside of a highly customizable development environment is the opportunity for developers to accidentally (of course) remove necessary features from the IDE. For example, you might remove necessary items from a toolbar or a menu. Or, through innocent experimentation, rearrange tool windows into an unusable layout. In earlier versions of Visual Studio, you could restore individual items within the IDE (for example, by going to the Window menu and choosing the Reset Window Layout command). Most of these reset tools are carried forward in Visual Studio 2005. However, individual reset tools encompass just a small portion of IDE functionality, and the fact that they are scattered throughout the IDE can sometimes make it difficult to find the appropriate one.

The Import and Export Settings Wizard also lets you Reset IDE settings option to change the IDE environment to a work style defined in a number of predefined settings files. These settings are installed with Visual Studio 2005, and include specific customizations for window layouts, toolbars, and menu commands that reflect the common preferences related to specific programming orientations, such as VB.NET, C++, C#, Web, or J#.


Figure 3-4. Reset IDE settings

**Tip   **If your settings reach a state where you can’t use the IDE, or they prevent you from accessing the Import/Export Settings dialog, restore the default settings by restarting Visual Studio 2005 from a command prompt using a reset switch, as follows: devenv / resetsettings

If you need to reset only certain settings categories, use the Import IDE Settings From A File option. You can select settings from one of the default settings files or a local settings file. You can also browse to a file located in a folder other than the Visual Studio 2005 default folder. For example, in a situation where your development team shares a settings file, the file might be located on a network share. As shown in Figure 3-5, once you have selected the file, the tree view titled Settings Available To Import lists the settings stored in the file. By selecting or clearing items displayed in the list, you can choose which settings to import. The Import IDE Settings From A File option allows you to change all or a portion of your settings from a .vssettings file.


Figure 3-5. Import specific IDE settings

Help and Community Integration

Visual Studio 2005 represents significant advances both in the content of Help information and in the tools for accessing that information. These improvements also include more comprehensive integration with community-based resources.

Then and Now

Before reviewing what is new and improved in the Help system, for some perspective let’s review how previous versions of Visual Studio provided ways to get help, highlighting the limitations of each:

  • F1: This was at best a "hit or miss" tool. Sometimes F1 returned the right answer. Other times, it showed the Dynamic Help window—that provided help on the "Code and Text Editor"—which was rarely the area in which you needed assistance.
  • Table of Contents (TOC): You can browse the content tree of a TOC to look for topics unrelated to a current topic. Yet, while this may sometimes yield useful information, it can also be time consuming and fruitless.
  • Index: In certain situations, the Help Index is still a good option for locating useful information. For example, if you already know the .NET Framework class name in which you are interested, the Index works well. It falls short, however, when you are looking for conceptual information.
  • Search: The major drawback of searching was that it could return up to five hundred results in a random order.
  • Web-based search: While results vary depending on your preferred search engine, this remains the help tool of choice for many developers. It not only avoids the shortcomings of earlier Visual Studio help tools, but it also provides access to additional information available on the Internet.

Visual Studio 2005 offers the following significant updates to these tools to allow you to access help content more efficiently:

  • F1: Improvements to the metadata on Help topics make F1 more consistently helpful, even if you’re not in the context of a project.
  • Search: The filtering mechanism is improved over earlier versions of Visual Studio, thereby delivering results that include topics that more closely match your search criteria. Another important improvement is that the results include a dynamically generated abstract of each returned item.
  • How Do I: This is a new tool, shown in Figure 3-6, for accessing the help system that presents a hierarchical organization of common developer tasks. For Visual Basic .NET developers, the tool provides hundreds of tasks, and each task contains technical instruction content and sample code that a developer can easily paste into the code editor.
  • Help Favorites: Earlier versions of Visual Studio included an integrated Favorites tool, but only for Internet Explorer links. The updated Help Favorites tool lets you save help-specific favorites, including the parameters of search queries.

Click here for larger image

Figure 3-6. "How Do I" Help (Click on the image for a larger picture)

Using Online Help Content

As with earlier versions of the development environment, Visual Studio 2005 provides direct access to content found at Web sites like CodeGuru and Net247. These and other .NET- focused Web sites are members of a group known as the .NET CodeWise Community. The CodeWise Community is a Microsoft-sponsored community of Web sites providing independent expertise in Microsoft developer tools and technologies. If you have accessed these sites in the past, you already know that contributions from members of the developer community expand and enrich static help resources. While MSDN content provides breadth of coverage, community content complements this with depth and context for areas important to real- world developers. In addition to extending help content and providing additional code samples, community-based Web sites also provide other resources, like message forums.

In a step forward from previous versions of the IDE, Visual Studio 2005 integrates content from CodeWise Community member sites directly into the help system. When you search for help on a topic such as generics from Visual Studio 2005, for example, the search might return a list of local MSDN topics, a list of MSDN online topics, and a list of links to relevant pages on CodeWise Community sites. This innovative feature gives you easy-to-use, direct access to the newest and most popular code samples and technical articles in the community, presented alongside the comprehensive static content available from MSDN. Moreover, this represents a significant advantage over performing ad hoc Web-based searches, where you need to validate for yourself whether the information you find is technically accurate. Configure online help resources, including CodeWise Community providers, in the Help category of the Options dialog box as shown in Figure 3-7.


Figure 3-7. Configuring online help resources

Project Enhancements

The most immediate productivity enhancement you’ll encounter with Visual Studio 2005 is the ability to create new projects without having to specify a storage location. The inspiration for this change came from the common experience of developers who create projects for testing code or building prototypes that they will use only once. Rather than committing these projects to disk as a new solution, the IDE gives you control of whether or not to save the project.

This enhancement works in a way similar to creating a new document in Microsoft Word, where you can open a document, type some text, print it, and then exit Word without saving the document. The same process applies to projects created in Visual Studio 2005; you can build a new application, run it in the debugger, add project items and resources, and even compile the application before saving. (The New Project dialog box is shown in Figure 3-8.) As with Word, Visual Studio 2005 holds the unsaved files in temporary file storage until you choose to either save them to a permanent location or discard them when you close the project. If you choose to discard them, Visual Studio 2005 removes the project and all its associated files from temporary storage. These are also known as "zero-impact" projects.


Figure 3-8. Visual Basic project templates

Visual Studio 2005 also introduces a number of new project item types. Many item types provide templates for common user interface elements, including a Login Form, an About Box, and an Explorer Form template, which is shown in Figure 3-9.


Figure 3-9. Project item types

Project Designer

In prior versions of Visual Studio, you could manipulate project properties by using a dialog box accessible from the project menu. Because dialog boxes are modal, you needed to first open the properties dialog box, change a setting, close the dialog box, and then continue working on your code. Throughout the course of a typical development cycle, you likely returned to the project properties many times. Perhaps you wondered to yourself, "Wouldn’t it be nice if I could leave these properties open all the time for easier access?"

The Project Designer addresses the need for easier, more consolidated access to project properties. When you create a new project in Visual Studio 2005, you’ll find an additional project element, named My Project, listed in Solution Explorer. (See Figure 3-10.) Opening this item displays the Project Designer in the main editing window of the IDE.


Figure 3-10. My Project

The Project Designer provides nonmodal access to project properties, making them as easy to get to as code files or form designers. If you’re familiar with earlier versions of Visual Studio, you’ll notice that the Project Designer panes consolidate properties that used to be contained in the properties dialog box and other areas of the IDE, while other panes provide configuration tools for features introduced with the .NET Framework 2.0 (such as ClickOnce publishing).

Note   For details on the Publish and Security panes, see Chapter 8, "Deploying Applications."

Application Pane

The Application pane, shown in Figure 3-11, is one of the places where the designer incorporates settings from the properties dialog of prior versions of Visual Studio. This pane also introduces new items for defining the behavior of your application. Once you open the Project Designer, the Application pane is available as a tab in the Visual Studio 2005 document window. (Alternatively, you can open the Project Designer by right-clicking the project in Solution Explorer and selecting the Properties menu command, or select the Project | <Project Name> Properties menu command.)

Click here for larger image

Figure 3-11. The Application pane (Click on the image for a larger picture)

Here are a few of the new and updated settings:

  • Startup Form: Visual Studio 2005 includes a new application framework to handle many of the common windows application tasks, especially those related to application startup. As a result, you rarely have to write a traditional Sub Main. Instead, you specify the startup form, and if you need other initialization code to run, you add it to the application events (listed in Table 3-1). You can still specify a form or Sub Main procedure by disabling the application framework.
  • Enable XP Visual Styles: This setting is enabled by default, and it allows your applications to use the Windows XP themes present on the host operating system. However, you might encounter certain situations where your applications use controls from a previous version of Windows XP themes, in which case you should disable Windows XP themes to preserve the desired look and feel of the application.
  • Make Single Instance: When you click a particular Windows application several times (Media Player, for example), the application is launched only one time. Other applications (Calculator, Notepad, and so forth) launch separate instances of the program each time you click the icon. Selecting this setting allows you to set the launch behavior of the application as a single instance; if this setting is not selected, the application can launch multiple instances.
  • Save My.Settings on Shutdown: As mentioned previously, it is now easy to configure strongly typed settings for your applications. If this option is checked, then changes made programmatically to those settings are automatically resaved when the application exist.
  • Shutdown Mode: This option determines what event signals the shutdown of the application. For a Windows Forms application, for example, you can choose to shut down the application when the startup form closes or when the application exits.
  • Splash Screen: With this setting, it is simple to configure a spash screen for your application. This screen will appear for a pre-determined amount of time, and then vanish when the main form appears.
  • View Application Events: Clicking this button opens the ApplicationEvents.vb code module. ApplicationEvents.vb contains a partial MyApplication class (defined within the My namespace). The MyApplication class exists for the express purpose of containing handlers for application events, described in Table 3-1.

Table 3-1. MyApplication Events

Name Description
Startup Raised when the application starts
Shutdown Raised when the application exits
UnhandledException Raised when an unhandled exception occurs in the application
StartupNextInstance Raised when a user attempts to launch a separate instance of the program for applications configured to run as a single instance
NetworkAvailabilityChanged Raised when the status of the underlying network connection changes

Managing Assembly Information

In previous versions of Visual Studio for the .NET Framework, you typically managed global assembly attributes in the AssemblyInfo.vb code file. As with any other code file in the project, to change the assembly attributes, you needed to open the file in the code editor and update the attributes as necessary. The following are a few common attributes found in AssemblyInfo.vb:

<Assembly:  AssemblyTitle("IDE  Enhancements")>
<Assembly:  AssemblyDescription("New  Visual  Studio  2005  IDE  features")>
<Assembly:  AssemblyCompany("3  Leaf  Solutions")>
<Assembly:  AssemblyProduct("Moving  to  Visual  Studio  2005")>
<Assembly:  AssemblyCopyright("2005")>
<Assembly:  AssemblyVersion("")>
<Assembly:  AssemblyFileVersion("")>
<Assembly:  ComVisible(False)>

In Visual Studio 2005, assembly attributes are still stored in AssemblyInfo.vb, but the file is now hidden in Solution Explorer by default. The Application pane provides access to these attributes via the Assembly Information dialog box shown in Figure 3-12. This dialog box is an interface to the underlying assembly attributes; any changes you make to an item listed in this dialog box is automatically written to the underlying AssemblyInfo.vb file. (Of course, you can still access the underlying code file and make changes directly if you prefer.)


Figure 3-12. Assembly Information dialog

Signing Pane

Every managed assembly that executes on the common language runtime (CLR) is governed by the Code Access Security (CAS) permissions associated with that assembly. During execution, the CLR evaluates the assembly’s requested permissions and either grants or denies those permissions, in part by using evidence provided to the CLR about the identity of the code. As a way of establishing the assembly’s identity, the Signing pane (shown in Figure 3-13) allows you to add either a key file (.snk) or a key stored in a key container to the project. The compiler uses that key to sign the assembly with a strong name. To accommodate situations where developers need to do a prerelease build but only have access to the public key, the pane also provides a check box to enable delayed signing.

Important   For ClickOnce applications, a signing key is required for publishing. The key is used to strong-name-sign both the application and deployment manifests. This topic is discussed in detail in Chapter 8, "Deploying Applications."

Click here for larger image

Figure 3-13. Signing pane (Click on the image for a larger picture)

References Pane

You can still access project references and Web references from the project menu as in previous versions of the IDE. However, Visual Studio 2005 adds an additional point of access to these items in the References pane, shown in Figure 3-14. Use the References pane to manage imported namespaces and assembly and Web service references. A significant benefit of this alternative view is that it consolidates project references in a single UI component. The pane contains tools for setting one or more reference paths and for identifying referenced assemblies that are not used in the project and, as a bonus, it also lets you manage namespace import settings.

Click here for larger image

Figure 3-14. References pane (Click on the image for a larger picture)

Compile Pane

In addition to setting default compiler options for each of the various build configurations, the Compile pane (shown in Figure 3-15) also lets you specify individual notification behaviors (such as Warning, Error, or None) for different compilation conditions. Use this pane to set conditional notification options.

Click here for larger image

Figure 3-15. Compile pane (Click on the image for a larger picture)

You can also access the Build Events dialog box from this pane. As with earlier versions of the IDE, use this dialog box to specify pre-build and post-build command-line events, as well as to specify the condition under which a post-build event fires. The condition under which the post-build event executes can be Always, On Successful Build, or When The Build Updates The Project Output.

MSBuild Integration

Visual Studio 2005 introduces a new build engine called named MSBuild, which is integrated into the Visual Studio 2005 IDE to dramatically improve the build process. While MSBuild operates under the covers in the Visual Studio 2005 IDE, it has also been specially designed to execute build tasks from a command line.

Resources Pane

The Resources pane of the Project Designer provides a comprehensive resource manager for your project. (See Figure 3-16.) Resource categories include localization strings, images, icons, sound files, and text files. You can access each of the various resource categories from the Categories drop-down list. To add a resource—such as a string, for example—simply type the name of the resource and its associated value in a table displayed in the user interface.

Click here for larger image

Figure 3-16. Resources pane (Click on the image for a larger picture)

Additionally, for image and icon resources, you can either add an existing image or icon file, or you can create a new image or icon directly inside the development environment (see Figure 3-17).

Click here for larger image

Figure 3-17. Icon designer (Click on the image for a larger picture)

Resources and Framework Integration

The Resources pane is a good example of a place in the IDE that has been closely integrated with the enhanced .NET Framework. Items managed in the Resources page are automatically available in code through the My namespace via the Resources module, which contains a representation of the project resources in code. Synchronization between items managed in the Resources pane and the underlying code file is managed transparently by the Strongly Typed Resource Builder, an integrated Visual Studio 2005 tool. When you make changes to elements in the Resources page, this tool writes those changes to the Resources module, which in turn is found in the Resources.Designer.vb file. By default, Resources.Designer.vb (and a number of other automatically generated project files) is hidden from view in Solution Explorer. You can display hidden files in Solution Explorer by clicking the Show All Files button.

The code generated by the Strongly Typed Resource Builder is equivalent to the output class produced by the ResGen command-line utility. The key advantage this utility has over ResGen is that you don’t need to run it every time you update the resource file; Visual Studio manages the updates for you automatically.

Settings Pane

A common application development task is providing a mechanism for storing application and user settings. This might include state information such as database connection strings, the position and size of forms, preferences for toolbar position and contents, URLs for Web services—the list goes on. Earlier versions of the .NET Framework offered different options for storing settings. For example, you could use dynamic properties or you could add your own section to the application configuration file. The .NET Framework 2.0 represents an evolution of these technologies. The .NET Framework 2.0 introduces new classes for managing application and user settings as strongly typed objects. The classes have been integrated into the Visual Studio 2005 IDE using the Settings pane of the Project Designer.

  • Levels of Functionality: The Settings pane itself has a number of levels of functionality. First, you can create settings for virtually any CLS-compliant type. It also includes a special type for database connection strings. In fact, when you create a new database connection, Visual Studio automatically adds the connection string to the project settings.

    The user interface includes an input table for specifying the name of each setting, its type, and the value for the setting. Another important attribute is whether the setting is applied application-wide or for an individual user. The table includes a column that lets you set the scope to either of these two options.

  • Settings and Framework Integration: As with items defined in the Resources pane, Visual Studio 2005 automatically provides strongly-typed access to the settings managed in the Settings pane. And also as with project resources, settings are available programmatically via the My namespace. Yet while the My.Resources object allows only read-only access to project resources at run time (because resource elements are represented in code as read-only properties), the My.Settings object exposes user settings as read/write properties, which of course means that you can change them at run time.

    The My.Settings class derives from the ApplicationSettingsBase class. This relationship between the two provides My.Settings with two methods for manipulating user settings: a Save method, and a Reset method. The programming model is very simple for changing user settings. In code, all you need to do is update the user setting exposed as a property of the My.Settings object and then call the Save method to persist the change. To change all the user settings back to the last saved settings, call the Reset method.

    Note   The ApplicationSettingsBase class is featured in many areas of the .NET Framework. For example, it is inherited by a number of Windows Forms controls to provide run-time access to the properties of the control, such as size, position, and so on. This class also provides the necessary functionality to persist run-time changes to control properties as user settings. For more details on how user settings have been enabled in Windows Forms controls, see Chapter 5, "Constructing User Interfaces."

The My.Settings object also exposes the events inherited from the ApplicationSettingsBase class. Those events include PropertyChanged, SettingChanging SettingsLoading, and SettingsSaving.

New and Improved Tool Windows

The Visual Studio 2005 IDE includes a number of tool windows designed to improve productivity and reduce the amount of code you need to write. This section reviews some of the productivity-enhancing tool windows in Visual Studio 2005 IDE.

Code Editor

If you are familiar with the documentation feature of the C# code editor from past versions of Visual Studio, you’ll recognize another new feature of the Visual Basic .NET Code Editor that allows you to automatically insert the tags for generating XmlDoc comments. To use this feature, place your cursor above a member in the code file and type a single quote three times. This generates the following XmlDoc comment tags:

'''  <summary>
'''  </summary>
'''  <param  name="fireDate"></param>
'''  <remarks></remarks>
Public  Sub  Fire(ByVal  fireDate  As  Date)
      .  .  . 
End  Sub

While this feature has been available for a number of years in the C# code editor (which uses three forward slash keystrokes instead of single quotes), it is nevertheless a timely addition to the Visual Basic .NET Code Editor.

Data Preview Dialog

The Data Preview dialog box allows you to preview the data returned by any DataComponent query in your project. To preview data, open the Data Preview dialog from the Data Designer window (shown in Figure 3-18). You can also access the Data Preview dialog from the Data Sources window.


Figure 3-18. Open the Data Preview dialog from the Data Designer

In the Data Preview dialog, first select the object that you want to preview. If the object is a parameterized query, enter parameter values in a separate control in the dialog box. Then click the Preview button to execute the query; the resulting data is displayed as shown in Figure 3-19.

**Note   **Queries that change data in the database (such as the INSERT, UPDATE, and DELETE queries) will not affect the database when executed in the Preview Data dialog box.


Figure 3-19. The Data Preview Data dialog

Document Outline

In earlier versions of the Visual Studio 2005 IDE, the Document Outline window allowed you to view the structure of an HTML or ASPX page by providing a visual representation of the markup hierarchy. The window displays the HTML tags, script elements, and controls on the page by using a tree view that you can expand or collapse to focus on specific areas of the page. And by double-clicking any item in the view, you can navigate to it directly on the page. This functionality has been carried forward to Visual Studio 2005 and extended to provide the same visibility into the elements on a Windows Form.

The Document Outline window for a Windows Form layout (shown in Figure 3-20) provides an easy way to manage controls on a form. As with the original incarnation of the Document Outline window, you can expand and collapse containing items as you scroll through the outline. To select a control in the Form Designer, click the item in the tree view. You could reasonably argue that given the complex control layout common in any nontrivial Windows Form application—which might contain a number of deeply nested hidden components, or both— extending document outlining to forms provides a much bigger benefit to developers than it does for simple Web page editing. Additionally, you can also drag and drop controls from one container to another within the container hierarchy.


Figure 3-20. The Document Outline window

**Note   **Rearranging controls in the Document Outline window is available only for Windows Forms, not Web pages.

Window Docking Enhancements

Another noteworthy enhancement to the development environment is the introduction of docking guides (Figure 3-21). When you rearrange windows within the IDE, changeable icons appear on the design surface to guide you to areas where the window can be placed. If you hover your mouse over the icon, the associated area of the IDE becomes shaded to indicate where the window will appear if you choose to complete the operation.

Click here for larger image

Figure 3-21. Docking guides (Click on the image for a larger picture)

Class Designer

The Class Designer (shown in Figure 3-22) is a visual design tool for examining and manipulating the structure of classes and other types. The tool is fully integrated with the source code underlying the types displayed in the designer; if you make a change to a property name, for example, the code file automatically updates to reflect the change. Conversely, changes made in the source code immediately affect the appearance of its associated object in the designer. This synchronized editing relationship between designer and code makes it easy to create and configure CLR types visually.

Click here for larger image

Figure 3-22. The Class Designer (Click on the image for a larger picture)

Writing Correct Code

Visual Studio 2005 includes a number of tools—some are enhancements of old features and some are new features—geared toward the common objective of making it easier for developers to write code correctly at design time. In the following sections, we’ll look at some key areas in the IDE that make the coding experience in Visual Studio 2005 less susceptible to error.

IntelliSense Enhancements

The Microsoft IntelliSense technology carries forward key features of prior versions of Visual Studio, such as automatically tracking the most often-used member of a particular type. In addition, IntelliSense has been improved to include a facility for choosing whether to display all the members of a type (as shown in Figure 3-23) or just the most commonly used members.


Figure 3-23. The IntelliSense window

If the All button is selected, every member within the type (including hidden members) is displayed. If you click the Common button, the display changes to show only the most frequently used members of that type. If you work regularly with only a few properties and methods for a given type (particularly those with a large number of members), using IntelliSense in Common mode makes it much easier to locate those items while you’re typing in code.

Syntax Error Assistance

Past versions of the Visual Basic development environment have always distinguished themselves in one way or another in the area of providing design-time feedback, particularly when that feedback involved mistaken syntax. The Code Editor displays a squiggly line underneath an item of code containing an error. Placing the cursor over the squiggle displays a ToolTip briefly describing the problem. This form of design-time syntax checking has been an important feature of Visual Studio for many years now and is indeed helpful, but it is still basically hit or miss whether the error description gives you enough information to correct the problem.

With Visual Studio 2005, Microsoft adds to this functionality with the aim of enabling you to correct the error immediately. And it works using the same UI behavior you’re familiar with from past versions of Visual Studio. If you write code that the background compiler recognizes as a syntax error, the same squiggly line displays in the Code Editor. If you hover the cursor over the line indicating the error, not only does the same descriptive ToolTip display, but you will also see a small Help icon. Clicking the icon opens a dialog box that not only displays a description of the error, but also lists one or more solutions to the problem (see Figure 3-24). To implement one of the suggested fixes, all you need to do is click the appropriate fix.


Figure 3-24. Error Correction dialog

Design-Time Expression Evaluation

The Immediate window in Visual Studio 2005 is enhanced to allow you to test your code without having to execute the application. Assume, for example, that you have built a class in your Visual Basic .NET project and it contains a number of properties and methods. To test this code, you would either add a form or build a console wrapper to instantiate the class. When working in the Immediate window, you can instantiate an instance of the class, set properties on the object, and call its methods. In addition, if you have breakpoints set in your code and call a method or access a property from the Immediate window, execution stops at the breakpoint and allows you to step through the code as if you had explicitly invoked the debugger.

Error List and Task List

Users of earlier versions of Visual Studio will find that the functionality formerly provided entirely in the Task List is now distributed in two separate tool windows. The Error List is a new tool window that displays syntax error messages raised by IntelliSense and build errors reported by the Visual Basic .NET compiler. The scope of the Task List has been reduced in the Visual Studio 2005 IDE to display only reminders of work to be done, such as TODO tasks inserted into your code as comments.

Code Snippets

Code Snippets are another exciting new innovation of the Visual Studio 2005 IDE. This feature lets you insert into the Code Editor templates of code for performing common tasks. For example, imagine you want to add drag-and-drop functionality from a Windows Form control in your application. You might have written this code before on a recent project, but it is unlikely you have committed this to memory. Rather than hunting for the code in an old project file or scouring MSDN or the Web, code snippets let you capture the code in a reusable form that is available to you directly from the Code Editor.

Visual Studio 2005 installs with many useful code snippets categorized by function, as shown in Figure 3-25. These include snippets for reading and writing to files or for validating the format of a date or e-mail strings, just to name a few.


Figure 3-25. Code snippets

Code snippets are also validated by scope. This means that only the code snippets that are appropriate for your current position within the code—for example, within a method or function—are available in the menu selections.

Symbolic Renaming

If you’re like many developers, when you begin a new Visual Basic .NET project you tend to use the default names for forms and controls and other code elements. Sometime later, when the application has taken shape, you will rename items according to the naming conventions used in your organization. It is a tedious but necessary housekeeping chore if your goal is to write professional code. The symbolic renaming tool helps ease the pain of renaming code elements—and removes the risk of introducing unwanted syntax errors—by providing a simple-to-use method for globally updating names. To use this feature in the Code Editor, right-click an item in the code and select Rename from the context menu, as shown in Figure 3-26.


Figure 3-26. Access the symbol Rename tool from the Code Editor

In the Rename dialog, type the new name of the symbol, as shown in Figure 3-27.


Figure 3-27. The Rename dialog

Debugger Enhancements

Visual Studio 2005 offers a number of tools for viewing data in the debugging environment. Many of these tools have been around for several versions of Visual Studio (the Watch, Locals, and Autos windows, for example). These tools provide many different views into your application data. Still, you might encounter scenarios where it is still difficult to examine data during debugging. In the sections that follow, we’ll explore enhancements to the debugger environment and tools that make it easier for you to diagnose and remedy errors at run time.


DataTips have always been an excellent way to quickly view simple data types in the debugger. However, in earlier versions of Visual Studio, for complex data types you saw the name of the type and not the data contained therein, as shown in Figure 3-28. A key improvement to DataTips in Visual Studio 2005 is that they now display the members of complex data types, as shown in Figure 3-29.


Figure 3-28. Simple data type


Figure 3-29. Complex data type

Another enhancement to DataTips is that you get a context menu for both simple types and each member of a complex type. The context menu contains items for adding a watch for the selected type, editing the value for the type, or viewing the hexadecimal value for the type. (See Figure 3-30.)


Figure 3-30. DataTip options

You can also edit member values directly in the DataTip by selecting the value and then typing the new value over it, as shown in Figure 3-31.


Figure 3-31. Updating a member value

After you finish changing the member variable, the DataTip automatically displays the updated value, as shown in Figure 3-32.


Figure 3-32. The updated member value


A more sophisticated data inspection tool for the Visual Studio 2005 debugger is the visualizer. A visualizer is a dialog box that displays a variable or object in a way that makes sense for a particular data type. String variables, for example, can be visualized as HTML, XML, or plain text by using one of the four default visualizers included with Visual Studio 2005.

All the various debugging tools—DataTips, the Watch window, the Locals window, or the Autos window—display a magnifying glass icon beside a data type that can be viewed using a visualizer. Clicking the magnifying glass allows you to select a visualizer to display the data type of the corresponding object.

In addition to the three text-based visualizers just mentioned, a dataset visualizer is also included by default to let you more easily inspect data contained in a dataset.

Tip   Additional visualizers might be available for download from Microsoft in the future.

Exception Assistant

The Exception Assistant is a new debugging tool introduced with Visual Studio 2005. When a run-time exception occurs, it appears as a dialog box displaying details about the error. Significantly, the Exception Assistant dialog box also includes troubleshooting tips for handling the exception.

The dialog box title bar displays the type of the error, and below that, a description of the error. At the top of the assistant is the troubleshooting tips section, which in most cases will provide links to help content to aid you in diagnosing the problem. In many cases, however, the assistant will offer step-by-step instructions for correcting the error.

Customizing Data Display

Visual Studio 2005 offers several options for customizing the display of data in the debugger. The following section reviews three techniques you can use to manipulate the way data is displayed in the debugger.

Override the ToString Method of Custom Types

The simplest technique for altering the data displayed in the debugger for a custom type is to override the base object ToString method, as follows:

Overrides  Function  ToString()  As  String
   Return  Me.FirstName  &  "  "  &  Me.LastName
End  Function

Using the Debugger Display Attributes

Other situations call for more control of how the data is displayed. You might want to format the underlying data differently or limit the amount of data presented in the debugger. The .NET Framework provides three attribute classes for controlling how data is displayed in the debugger:

  • DebuggerDisplayAttribute: Apply this attribute to add a summary to a type within the data windows in the debugger. For example, the following code shows how to add a summary to a custom data type:

    <DebuggerDisplay("Associate  (  {  FullName  }  ")  > _
    Public  Class  Associate
    Private  FullName  as  String
    .  .  .
    End  Class

    The constructor for the DebuggerDisplayAttribute accepts a string format specification. The text inside the curly braces can represent a property or method of the containing class. Note that you can use both private and public members of the class.

  • DebuggerBrowsableAttribute: Apply this attribute to a member in a class to control whether or not it is displayed in the debugger.

    Public  Class  Associate
    <DebuggerBrowsable(  False  )  >  _
    Public  Property  SocialSecurityNumber  As  String
    .  .  .
    End  Property
    End  Class

    In the preceding pseudo code, the DebuggerBrowsableAttribute applied to the SocialSecurityNumber property of the Associate class will prevent that property from displaying in the debugger windows.

  • DebuggerTypeProxyAttribute: This attribute provides the most flexibility by allowing you to substitute the attributed member with a custom debugger type.

    <DebuggerTypeProxy(  GetType(  AssociateProxy  )  )>  _
    Public  Class  Associate
    .  .  .
    End  Class

The input parameter for the DebuggerTypeProxyAttribute constructor specifies the class used as a proxy for displaying data of that type. As a best practice, you should implement the proxy class as a nested internal class of the data type to which it is applied. By doing this, the nested class can have full access to the private members of the type it is describing.


The Visual Studio 2005 integrated development environment includes a number of new and improved productivity features. The IDE has also been redesigned with a view toward providing developers with more direct access to the .NET Framework components, such as the new settings and resource architecture.

© Microsoft Corporation. All rights reserved.