Visual Studio 2005 Versions from Express through Team Suite


First we should clarify one thing that’s common across all versions of Visual Studio 2005. This version of the IDE was designed to work with version 2.0 of the .NET Framework. Microsoft introduced Visual Studio 2005 with .NET 2.0 and the two items went through development as a single unit. It will be important to remember that Visual Studio 2005 was optimized for .NET 2.0, as opposed to .NET 1.x or .NET 3.0.

Similar to the way that Visual Studio 2003 was focused on .NET 1.1 and Visual Studio .NET (2002) was focused on .NET 1.0, each version of Visual Studio is optimized for a particular version of .NET. Similarly, even though the title of this book is .NET 3.0, the various versions of Visual Studio 2005 are actually optimized for .NET 2.0, and with the exception of unsupported add-ons, don’t support the new features of .NET 3.0.

Fortunately, Microsoft chose to keep Visual Basic and ASP.NET unchanged for the .NET 3.0 Framework release. However, when looking at the new .NET 3.0 Framework elements such as Windows Presentation Foundation, Windows Communication Foundation, and Windows Workflow Foundation, these items need to be addressed outside of Visual Studio. Thus, while Visual Studio 2005 is separate from Visual Basic and .NET development, in practical terms the two are tightly coupled.

With those ground rules in place, what versions of Visual Studio 2005 are available and what are the primary differences between them? As already mentioned, Visual Basic 2005 Express is at the bottom tier in terms of price and features. It is accompanied there by Visual Web Developer 2005 Express Edition for those developers who are developing Web applications as opposed to desktop applications. These two tools are separate, but both support developing different types of Visual Basic applications, and coincidentally both are free.

In addition, these two development tools ship with two additional components covered briefly here: MSDN Express Edition and SQL Server 2005 Express Edition. MSDN is, of course, the Microsoft Developer Network, which has placed most of its content online. It’s the source for not only the core language documentation for Visual Basic, but also articles on almost every product oriented to developers using Microsoft technology. Full versions of Visual Studio ship with the full MSDN library so that you can access its content locally. However, the Express Edition tools actually ship with a pared-down 200 MB set of documentation files - of course, that’s still a lot of documentation.

Similar to the language and Web-based tools, Microsoft has a SQL Server Express Edition package. This package actually has a history, in that it replaces the MSDE database engine that was available with SQL Server 2000. The new SQL Server Express engine provides the core SQL Server 2005 database engine. Unlike MSDE, it also offers a free management application available via separate download from Microsoft.

When you install Visual Studio 2005, including the Express Editions, you are also given an opportunity to install this core database engine. The elements of this engine are freely redistributable, so if you are looking for a set of core database features based on ADO.NET, you can create your application and deploy your SQL Server 2005 Express Edition database without being concerned about licensing. SQL Server is covered in more detail in Chapter 14.

Getting back to the differences in versions, the Express Edition tools provide the core components necessary to create Visual Basic applications (Windows or Web) based on the core IDE. The following table provides a quick summary of what versions are available, including a description of how each extends Visual Studio:

Open table as spreadsheet

Visual Studio Edition

Description

Visual Basic 2005

Express Edition

This is the core set of functionality required for creating Windows-based applications. Includes the IDE with full local debugging support and support for three project types - Windows Application, Dynamic Link Library, and Console Application. Includes two starter kits, with additional starter kits available for download.

Visual Web

Developer 2005

Express Edition

This is the core set of functionality required for building Web applications. It supports both Visual Basic and C# and allows for local debugging of your Web application. Includes a starter kit.

Visual Studio 2005

Standard Edition

Provides a combined development language for the core Visual Studio languages (J#, VB, C# and C++). Adds the Object Modeling tool. Provides combined support for both Windows and Web applications and provides additional support for application deployment. It also provides support for Mobile Application Development, integration with a source control tool, and macros within Visual Studio.

Visual Studio 2005

Professional

Edition

Expands on Visual Studio Standard Edition with additional integration to SQL Server and support for XSLTs. Also allows for remote debugging of Web applications.

Visual Studio 2005

Tools for Office

A suite that can be combined with other Visual Studio 2005 products, this package provides support for Office integration with .NET 2.0. It supports only VB and C# but also adds native support for Microsoft Access 2003.

Visual Studio 2005

Team Edition for*

When Visual Studio 2005 was released, Microsoft provided three specialized versions of Visual Studio 2005 Team Suite, each of which contained everything from the previously mentioned versions (combine Visual Studio 2005 Professional Edition with Visual Studio Tools for Office) plus a subset of the Team Suite client tools. The editions were Team Edition for Architects, Team Edition for Developers, and Team Edition for Testers. Since then, Microsoft has announced a fourth edition, Team Edition for Database Developers. Each edition contains a subset of the full Team Suite of tools, and includes a client license for Microsoft Team Foundation Server. These must be purchased as part of an annual MSDN package.

Visual Studio 2005

Team Suite

The full Team Suite includes all of the core features of Visual Studio 2005 Professional Edition and Visual Studio Tools for Office. It also includes all of the tools from Visual Studio Team Suite - static code analysis, code profiling (performance testing), unit tests (which may be written in Visual Basic), application and deployment graphical design tools, Web and load-testing tools, and a variety of related tools to enhance development. This tool, like the Team Edition versions of Visual Studio, is focused on enabling developers to be productive in a shared collaborative environment. It works best when combined with Microsoft Team Foundation Server for source control and collaboration capabilities.

The Express Edition tools are best described as targeting students and hobbyists, not because you can’t create serious applications but because they provide only limited support for a shared development environment. For example, one of the starter kits available for Visual Basic 2005 Express Edition is a sample of integration with Lego’s Mindstorms. Again, the Express Tools are oriented toward a developer who works independently, while still providing full access to features of the Visual Basic language, which is why this chapter begins by using this version of the IDE.

Eventually, however, a developer needs additional tools and projects. This is where the full versions of Visual Studio 2005 (Standard and Professional) come in. With an increasing level of support for team development, the more advanced versions add macro support and, more importantly, an Object Modeling tool that is amazing. As discussed later in this chapter, the Object Modeling tool enables you to create a visual representation of the classes in your solution and then convert that representation into code. Moreover, the tool supports what is known as round-trip engineering. This means that not only can you use the graphical model to generate code, you can also take a project’s source files and regenerate an updated version of the graphical model - that is, edit that model in its graphical format and then update the associated source files.

Visual Studio Tools for Office (VSTO) is targeted primarily at enterprise developers, developers who work in corporate organizations (either as employees or consultant/contractors). This tool provides a way for users of the enterprise editions of Microsoft Office 2003 to extend these office productivity tools with applicationlike features. Many organizations use Microsoft Office for tasks that border on custom applications. This is especially true for Microsoft Excel. VSTO provides project templates based on these Microsoft Office products that enable, for example, a spreadsheet to retrieve its contents from an SQL Server database instead of the local file system. These tools provide the capability not only to manipulate data retrieval and saving, but also to customize the user interface, including direct access to the Task Pane and custom toolbar options within Microsoft Office products.

Visual Studio 2005 Team Suite and the various Team Edition products focus on extending a developer’s reach beyond just writing code. These tools are used to examine code for flaws, manage the deployment environment, or define relationships between applications. The suite is focused on tools that support repeatable software processes and best practices. They are geared toward examining source code for hidden flaws that might not cause the code to fail but might hide a hidden security flaw or make it difficult to maintain or deploy the application. More importantly, the suite includes tools for creating unit test tools that can attempt to cause the code to fail, whether through bad input data or heavy load. The Team Suite tools are focused on automating software development best practices for application teams, as opposed to actually writing the application.

Complete coverage of all of Team System warrants a book of its own, especially when you take into account all of the collaborative features introduced by Team Foundation Server and its tight integration with both Team Build and SharePoint Server. Team Foundation Server goes beyond just being a replacement for Visual Source Safe. It is the basis for true process-driven development, and it even includes documentation to help train your organization on two process models supported by Microsoft. The Team System extensions to the Microsoft software development suite are nontrivial, and are discussed in more detail at the end of this chapter.

Creating a Project from a Project Template

While it is possible to create a Visual Basic application working entirely outside of Visual Studio 2005, it is much easier to start from Visual Studio 2005. After you install Visual Studio you are presented with a screen similar to the one shown in Figure 13-1 for Visual Studio 2005 Express Edition. The default behavior is for the IDE to start by displaying this start page in its central section. The start page lists your most recent projects in the upper left corner, some tips for getting started below that, and a headline section below that. You may or may not immediately recognize that this content is essentially HTML text; more important, the right-side content is based on a Web Service call that retrieves and caches articles appropriate for your version of Visual Studio.

image from book
Figure 13-1

The start page looks similar regardless of which version of Visual Studio 2005 you are running. The idea is to provide a generic starting point either to select the application you intend to work on, to quickly receive vital news related to offers, as shown in the figure, or to connect with external resources via the community links.

Once here, the next step is to create your first project. Selecting File image from book New Project opens the New Project dialog, shown in Figure 13-2. This dialog provides you with a selection of templates customized by application type. One option is to create a Class Library project. Such a project doesn’t include a user interface; and instead of creating an assembly with an .EXE file, it creates an assembly with a .DLL file. The difference, of course, is that an .EXE file indicates an executable that can be started by the operating system, whereas a .DLL file represents a library referenced by an application.

image from book
Figure 13-2

Tip 

One of the ongoing challenges with describing the menu options for Visual Studio is that the different versions have slight differences in look and feel too numerous to mention. For example File image from book New Project in Visual Basic Express becomes File image from book New image from book Project in Visual Studio. Thus, your display may vary slightly from what is shown or described here, although we attempt to showcase significant differences.

Noteworthy in Figure 13-2 are the starter kits, which are included with Visual Basic 2005 Express Edition. These kits go beyond just the basic files associated with a generic project template and include source files associated with a specific application. You’ll also note that the dialog includes a reference to My Templates. This section of the New Project window enables you to install additional templates. For example, the Microsoft site for Visual Basic includes several additional starter kits for Lego Mindstorms, a blackjack game, and others you can install. Additionally, third parties such as Dot Net Nuke provide custom templates associated with their application. Dot Net Nuke is an excellent example of this, and the version 4.4 starter kit package installs three templates in Visual Studio, two in Visual Basic and one in C#.

In order to keep the discussion of project templates in context, Figure 13-3 is an example of the same dialog opened from Visual Studio 2005 Team Suite. In this context, note that not only do you have additional project templates related to Visual Basic, but another pane that groups the templates into project types has been added. Figures 13-2 and 13-3 have different display options selected in the upper-right corner related to the size of the template icons only.

image from book
Figure 13-3

A quick note regarding the New Project dialog: Not all project types are listed within this dialog. If you want to create an ASP.NET 2.0 website, you need to start that process by creating a new website instead of creating a new project. This option is not available to Visual Basic Express users; instead, these users should install the Visual Web Developer 2005 Express Edition, which has a similar user interface (not shown here). Finally, note that Visual Studio 2005 Service Pack 1 added the ASP.NET 1.x application projects back into this dialog, as well as a template for Outlook-based VSTO projects.

Expanding the top level of the Visual Basic tree in Figure 13-3 shows that a project type can be further separated into a series of categories:

  • Windows - Projects used to create applications that run on the local computer within the CLR. Because such projects can run on any operating system (OS) hosting the framework, the category “Windows” is something of a misnomer.

  • Office - Visual Studio Tools for Office (VSTO). These are .NET applications that are hosted under Office 2003. Note that templates are provided for Excel and Word only.

  • Smart Device - These are projects that target the .NET Compact Framework. Such applications may run on one or more handheld devices and make use of a different runtime environment from full .NET applications.

  • Database - This template creates a project that supports classes that will run within SQL Server 2005. All versions of SQL Server 2005 (from Express through Enterprise) support the .NET Framework as part of their runtime, and such projects have a unique set of runtime constraints. This is a very different project template from the Database project template provided under Visual Studio 2003 and still available under the Other Project Types option.

  • Starter Kits - The same starter kits shown in the default view for the Visual Basic 2005 Express Edition are available under this section.

  • Test - This section is available only to those using Visual Studio Team Suite. It contains the template for a Visual Basic Unit Test project.

  • Web - With Visual Studio Service Pack 1, the ASP.NET 1.x project file-based Web applications were restored to Visual Studio 2005. ASP.NET eliminated the need for Web applications to use project files; however, some developers found this counterintuitive and Microsoft restored the capability to identify the files of a Web application as part of a project file.

Visual Studio has other categories for projects, and you have access to other development languages and far more project types than this chapter has room for. For now, you can select a Windows Application project template to use as an example project for this chapter.

For this example, use ProVB.NET as the project name and then click the OK button. Visual Studio takes over and uses the Windows Application template to create a new Windows Forms project. The project contains a blank form that can be customized, and a variety of other elements that you can explore. Before customizing any code, let’s first look at the elements of this new project.

The Solution Explorer

While the solution window both exists and is applicable for Express Edition users, it will never contain more than a single project. Those with a version of Visual Studio above the Express Edition level have the capability to leverage multiple projects in a single solution. A .NET solution can contain projects of any .NET language and can include the database, testing, and installation projects as part of the overall solution. The advantage of combining these projects is that it is easier to debug projects that are in a common solution.

Before discussing these files in detail, let’s take a look at the next step, which is to reveal a few additional details about your project. Click the second button on the left in Solution Explorer to display all of the project files, as shown in Figure 13-4. As this image shows, there are many other files that make up your project. Some of these, such as those under the My Project grouping, don’t require you to edit them directly. Instead, you can double-click on the My Project entry in the Solution Explorer and open the pages to edit your project settings. You do not need to change any of the default settings for this project, but the next section of this chapter walks you through the various property screens.

image from book
Figure 13-4

The bin and obj directories shown are used when building your project. The obj directory contains the first-pass object files used by the compiler to create your final executable file. The “binary” or compiled version of your application is then placed in the bin directory by default. Of course, referring to the Microsoft Intermediate Language (MSIL) code as binary is something of a misnomer, as the actual translation to binary does not occur until runtime when your application is compiled by the Just-In-Time (JIT) compiler. However, Microsoft continues to use the bin directory as the default output directory for your project’s compilation.

Figure 13-4 also shows that the project does not contain an app.config file by default. Most experienced ASP.NET developers are familiar with the use of web.config files. App.config files work on the same principle in that they contain XML, which is used to store project-specific settings such as database connection strings and other application-specific settings. Using a .config file instead of having your settings in the Windows registry enables your applications to run side by side with another version of the application without the settings from either version impacting the other. Because each version of your application resides in its own directory, its settings are contained in the directory with it, which enables the different versions to run with unique settings. Before we are done going through the project properties, we will add an App.Config file to this project.

Finally, the Solution Explorer includes your actual source file(s). In this case, the Form1.vb file is the primary file associated with the default Windows form. You’ll be customizing this form shortly, but before looking at that, it seems appropriate to look at some of the settings available by opening your project properties. An easy way to do this is to double-click on the My Project heading shown in Figure 13-4.

My Project Properties

Visual Studio displays a vertically tabbed display for editing your project settings. The My Project display shown in Figure 13-5, which is the view for users of Express Edition, is the same for all versions of Visual Studio. The project properties give you access to several different aspects of your project. Some, such as Signing, Security, and Publish, are covered in later chapters. For now, just note that this display makes it easier to carry out several tasks that once required engineers to work outside the Visual Studio environment.

image from book
Figure 13-5

Notice that you can customize your assembly name from this screen, as well as reset the type of appli cation and object to be referenced when starting your application. However, resetting the type of your application is not recommended. If you start with the wrong application type, it is better to create a new application, due to all the embedded settings in the application template.

In the next section you will look at a button for changing your assembly information, as well as the capability to define a root namespace for your application classes. Namespaces are covered in detail in Chapter 8, and unlike C#, which requires you to explicitly set the namespace in each source file, Visual Basic allows you to define a default.

Assembly Information Screen

Selecting the Assembly Information button from within your My Project window opens the Assembly Information dialog box. Within this dialog, shown in Figure 13-6, it is possible to define file properties, such as your company’s name and versioning information, which will be embedded in the operating system’s file attributes for your project’s output. The frame of the assembly file shows that by default it contains several standard values. This dialog is new to Visual Studio 2005 and replaces the way that engineers were forced to directly edit the XML contained in the AssemblyInfo.vb source file associated with an application.

image from book
Figure 13-6

Assembly Attributes

The AssemblyInfo.vb file contains attribute blocks, which are used to set information about the assembly. Each attribute block has an assembly modifier, shown in the following example:

 <Assembly: AssemblyTitle("")>

All the attributes set within this file provide information that is contained within the assembly metadata. These properties are displayed in the Assembly Information dialog, which is opened from the project’s properties page (select the Compile tab and then click the Assembly Information button). The attributes contained within the file are summarized in the following table:

Open table as spreadsheet

Attribute

Description

Title

Sets the name of the assembly, which appears within the file properties of the compiled file as the Description

Description

This attribute is used to provide a textual description of the assembly, which is added to the Comments property for the file.

Company

Sets the name of the company that produced the assembly. The name set here appears within the Version tab of the file properties.

Product

Sets the product name of the resulting assembly. The product name appears within the Version tab of the file properties.

Copyright

The copyright information for the assembly. This value appears on the Version tab of the file properties.

Trademark

Used to assign any trademark information to the assembly. This information appears on the Version tab of the file properties.

Assembly

Version

This attribute is used to set the version number of the assembly. Assembly version numbers can be generated, which is the default setting for .NET applications. This is covered in more detail in Chapter 21.

File Version

This attribute is used to set the version number of the executable files. This and other deployment-related settings are covered in more detail in Chapter 21.

COM Visible

This attribute is used to indicate whether this assembly should be registered and made available to COM applications.

Guid

If the assembly is to be exposed as a traditional COM object, then the value of this attribute becomes the ID of the resulting type library.

Not requiring developers to edit these settings directly at the XML level is one of the many ways in which Visual Studio 2005 was designed to enhance developer productivity over Visual Studio 2003.

Compile Settings

The Compile tab (see Figure 13-7) was previously shown in Chapter 2, but that was the version associated with Visual Basic Express Edition. This is one of two screens in the project settings that varies between versions of Visual Studio 2005. Specifically, there are two differences between this screen and the version shown in Chapter 2.

image from book
Figure 13-7

The first difference is at the top of the page, where you can select from Configuration settings. These settings refer to how your project is compiled in Debug or Release mode. Because these versions are only available when working with Visual Studio 2005 Standard or above, the discussion of these build configuration settings is handled later in this chapter in the section entitled “Build Configurations.” For Visual Basic Express Edition developers, just recognize that your application always builds in debug mode until you deploy/publish the project, in which case the project is automatically compiled in release mode.

As noted in Chapter 2, Visual Basic 2005 supports the default configuration elements Option Explicit and Option Strict, which automatically reset several of the settings shown in the dialog. In most cases, it is recommended that you enable both Option Explicit and Option Strict.

Below the grid of individual settings in Figure 13-7 is a series of check boxes. The first two relate to warnings and neither is enabled. They are mutually exclusive, and the first makes warning messages disappear, which is probably a bad idea. The alternative is to treat warnings like errors, which may cause more trouble than it’s worth, especially when you consider some of the items that generate warnings. Next, notice that near the bottom of the dialog is an option to generate XML comments for your assembly. These comments are generated based on the XML comments that you enter for each of the classes, methods, and properties in your source file. Unfortunately, these last settings are not available for Visual Basic 2005 Express Edition developers, although creating such comments, as shown later in this chapter, is possible even for Express Edition users.

Debug Properties

The Express Edition of Visual Basic 2005 supports local debugging. This means it supports not only the .NET-related Debug and Trace classes discussed in Chapter 9, but actual breakpoints and the associated interactive debugging available in all versions of Visual Studio. However, as noted, the full versions of Visual Studio provide enhanced debugging options not available in Visual Basic 2005 Express Edition. Figures 13-8 and 13-9 show the project debugger startup options from Visual Basic Express and Visual Studio 2005 Team Suite, respectively. Note that the Express Edition page has only three of the settings that are part of the more expensive version of Visual Studio.

As shown in Figure 13-8, Express Edition users have three options related to starting the debugger. The first is to apply command-line arguments to the startup of a given application. This, of course, is most useful for Console applications, but in some cases developers add command-line parameters to GUI applications. The second option is to select a different directory to be used to run the application. Generally, this isn’t necessary, but it’s desirable in some cases because of path or permission requirements or having an isolated runtime area.

image from book
Figure 13-8

Figure 13-9 shows additional options, beginning with Start Action. The default action shown is actually the only option available to Express users - which is to start the current project. However, Visual Studio 2005 developers have two additional options. The first is to start an external program. In other words, if you are working on a DLL or a user control, then you might want to have that application start, which can then execute your assembly. Doing this is essentially a shortcut from needing to bind to a running process.

image from book
Figure 13-9

Similarly for Web development, you can reference a specific URL to start that Web application. This is often a mixed blessing, as with ASP.NET 2.0 Visual Studio automatically attempts to start an ASP.NET application based on the page you are currently editing. This is a change from ASP.NET 1.x, which allowed you to define a start page. Because ASP.NET 2.0 does not use project files, the new behavior was introduced. In most cases it works just fine, but if you have a Web application requiring authentication, then in most cases it makes more sense to actually place that URL into the debug settings for your application.

The next set of options aligns with those of the Express Edition, except for that third item - Use remote machine. As noted, Visual Studio 2005 provides support for remote debugging, although such debugging is often more trouble than it’s worth. Using the Debug and Trace classes and effective error handling, it is generally easier to determine remote errors with existing tools. However, for those rare environments where an application only runs on a central server, and for which developers have the necessary permissions to run the debugger but not a copy of Visual Studio on that server, it is possible to leverage remote debugging.

Finally, as might be expected, users of Visual Studio 2005 who work with multiple languages and are given tools to tightly integrate with SQL Server have additional debuggers. The first of these is support for debugging outside of the CLR - what is known as unmanaged code. As a Visual Basic developer, the only time you should be using unmanaged code is when you are referencing legacy COM components. The developers most likely to use this debugger work in C++. The next option turns on support for SQL Server debugging, a potentially useful feature. In short, it’s possible, although the steps are not trivial, to have the Visual Studio debugging engine step directly into T-SQL stored procedures so that you can see the interim results as they occur within a complex stored procedure.

References

It’s possible to add additional references as part of your project. Similar to the default code files that are created with a new project, each project template has a default set of referenced libraries. Actually, it has a set of imported namespaces and then a subset of the imported namespaces also referenced across the project. This means that while you can easily reference the classes in the referenced namespaces, you still need to fully qualify a reference to, for example, a System.Collections.Generics.List class. For Windows Forms applications, the list of default referenced namespaces is fairly short:

Open table as spreadsheet

Reference

Description

System

Often referred to as the root namespace. All the base datatypes (String, Object, and so on) are contained within the System name-space. This namespace also acts as the root for all other System classes.

System.Data

Classes associated with ADO.NET and database access. This name-space is the root for SQL Server, Oracle, and other data access classes.

System.Deployment

Classes used for One Touch Deployment. This namespace is covered in more detail in Chapter 22.

System.Drawing

Provides access to the GDI+ graphics functionality

System.Windows.Forms

Classes used to create traditional Windows-based applications. This namespace is covered in more detail in Chapters 15 and 16.

System.XML

Root namespace for all of the XML classes

To review the details of the imported and referenced namespaces, select the References tab in your My Project display, as shown in Figure 13-10. Note that this tab enables you to check for unused references and even define reference paths. More important, it is from this tab that you select other .NET class libraries and applications, as well as COM components. Selecting the Add drop-down button gives you the option to add a reference to a local DLL or a Web Service.

image from book
Figure 13-10

When referencing DLLs you have three options: reference an assembly from the GAC, reference an assembly based on a file path, or reference another assembly from within your current solution. Each of these options has advantages and disadvantages. The only challenge for assemblies that are in the GAC is that your application is dependent on what is potentially a shared resource. In general, however, for assemblies that are already in the GAC, referencing them is a straightforward, easily maintainable process.

Similarly, referencing assemblies that are part of other projects in your solution is straightforward and highly recommended when possible. Because Visual Studio can map updates to these assemblies as they occur during a build of the solution, it’s possible for Visual Studio to automatically update the referenced assemblies in your executable project to be the latest build of the referenced DLLs that are part of the same solution. Note that the target needs to be an executable. Visual Studio will automatically update references between DLL projects in a common solution.

This is different from adding a reference to a DLL that is located within a specified directory. When you create a reference via a path specification, Visual Studio can check that path for an updated copy of the reference, but your code is no longer as portable as it would be with a project reference. More important, unless there is a major revision, Visual Studio usually fails to detect the types of changes you are likely to make to that file during the development process. As a result, you’ll need to manually update the referenced file in the local directory of the assembly that’s referencing it. In general, unless you have only the compiled version of that assembly, it’s best to leverage project references versus path-based references.

Resources

In addition to referencing other assemblies, it is quite common for a .NET application to need to reference things such as images, icons, audio, and other files. These files aren’t used to provide application logic but are used at runtime to provide support for the look, feel, and even text used to communicate with the application’s user. In theory, you can reference a series of images associated with your application by looking for those images based on the installed file path of your application. Doing so, however, places your application’s runtime behavior at risk, because a user might choose to replace, copy for profit, or just delete your files.

This is where project references become useful. Instead of placing the raw files onto the operating system alongside your executable, Visual Studio will package these files into your executable so that they are less likely to be lost or damaged. Figure 13-11 shows the Resources tab, which enables you to review and edit all your existing resources within a project, as well as import files for use as resources in your project. It even allows you to create new resources from scratch.

image from book
Figure 13-11

Note one little-known feature of this tab: Using the Add Resource drop-down button and selecting an image (not an existing image but one based on one of the available image types) will create a new image file and automatically open Microsoft Paint (for Express Edition developers); this enables you to actually create the image that will be in the image file. Users of Visual Studio 2005 have additional capabilities not supported by Visual Basic’s Express Edition.

For one thing, instead of needing to use Paint, Visual Studio provides a basic image editing tool, so when Visual Studio developers add a new image (not from a file), this editor opens within Visual Studio.

Additionally, within the list of Add Resource items, Visual Studio users can select or create a new icon. Choosing to create a new icon opens Visual Studio’s icon editor, which provides a basic set of tools for creating custom icons to use as part of your application. This makes working with .ico files easier in that you don’t have to hunt or purchase such files from the Internet and can instead create your own icons. However, images aren’t the only resources that you can embed with your executable.

Resources also apply to the fixed text strings that your application uses. By default, people tend to embed this text directly into the source code so that it is easily accessible to the developer. Unfortunately, this leaves the application difficult to localize for use with a second language. The solution is to group all of those text strings together and thus create a resource file containing all of the text strings, which is still part of and easily accessible to the application source code. When the application is converted for use in another language, this list of strings can be converted, making the process of localization easier. Localization is covered further in Chapter 6.

Settings

New support for application settings within .NET 2.0 is a major enhancement that is often overlooked. In .NET 1.x it was possible to create a settings file. As noted earlier in the discussion of the Solution Explorer, the default project template does not create any application settings; accordingly, an App.Config file is not needed and not created. App.Config files are XML files that define any custom application settings that a developer wants to be able to change without needing to recompile the application. Because these settings live in an XML file, they can be modified in between or even during application execution.

One original goal of .NET was to reduce the version conflict that occurs when a component has registered with global settings and two different applications are attempting to reference two different versions of that component. Because the settings were global and stored in the central system registry, the result was a conflict as the different applications each wanted its specific component and related settings.

.NET provided the capability to place version-specific project references in a local directory with the application, enabling two different applications to reference the appropriate version of that component. However, the second part of the problem was the central application settings. The App.config file provides the same capability, but its goal is allowing for local storage of application settings. Under .NET 1.x, support for application settings was still minimal, as most developers were still looking to the central system registry for this purpose. At the same time, the developer tools associated with settings were also minimal.

Fortunately, under .NET 2.0 this changed dramatically. Visual Basic 2005 provides significant support for application settings, including the Settings tab shown in Figure 13-12. This tab enables Visual Basic developers to identify application settings and automatically create these settings within the App.config file.

image from book
Figure 13-12

Figure 13-12 illustrates several elements related to the application settings capabilities of Visual Basic. The first setting is of type String. Under .NET 1.x, all application settings were seen as strings, and this was considered a weakness. Accordingly, you can see that the second setting, LastLocation, exposes the Type drop-down, illustrating that under Visual Basic 2005 you can create a setting that has a well-defined type.

However, strongly typed settings are not the most significant set of changes related to application settings. The very next column defines the scope of a setting. There are two possible choices - application wide or user specific. The settings defined with application scope are available to all users of the application. As shown in Figure 13-12, this example creates a sample connection string to store for the application.

The alternative is a user-specific setting. Such settings have a default value; in this case, the last location defaults to 0,0. However, once a user has read that default setting, the application generally will update and save the user-specific value for that setting. As noted by the Last Location setting, each user of this application might close the application after having moved it to a new location on the screen, and the goal of such a setting would be to reopen the application in the same location it was last seen. Thus, the application would update this setting value, and Visual Basic makes it easy to do this, as shown in the following code:

  My.Settings.LastLocation = Me.Location My.Settings.Save() 

That’s right - all it takes in Visual Basic 2005 is two lines of code that leverage the My namespace for you to update a user’s application setting and save the new value. Meanwhile, let’s take a look at what is occurring within the newly generated App.config file. The following XML settings demonstrate how the App.config file defines the setting values that you manipulate from within Visual Studio:

  <?xml version="1.0" encoding="utf-8" ?> <configuration>     <configSections>         <sectionGroup name="applicationSettings" type= "System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >             <section name="ProVB.NET.My.MySettings" type= "System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />         </sectionGroup>         <sectionGroup name="userSettings" type= "System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >             <section name="ProVB.NET.My.MySettings" type= "System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />         </sectionGroup>     </configSections>     <applicationSettings>         <ProVB.NET.My.MySettings>             <setting name="ConnectionString" serializeAs="String">                 <value>Server=local;database=Adventureworks</value>             </setting>         </ProVB.NET.My.MySettings>     </applicationSettings>     <userSettings>         <ProVB.NET.My.MySettings>             <setting name="LastLocation" serializeAs="String">                 <value>0, 0</value>             </setting>         </ProVB.NET.My.MySettings>     </userSettings> </configuration> 

As you can see, Visual Studio has automatically generated all the XML needed to define these settings and save the default values. It is possible not only to update application settings with Visual Basic, but also to arrange to encrypt those settings, although this action is outside the scope of what you can do from Visual Studio.

There are additional tabs related to your project’s properties, but these are primarily associated with deployment. Therefore, in the interest of getting to some code, let’s look at the source files that were generated when you created the ProVB.NET project from the Windows application template.




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

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