Você está na página 1de 5

What Is .NET? Microsofts .NET initiative is broad-based and very ambitious. It includes the .

NET Framework, which encompasses the languages and execution platform, plus extensive class libraries, providing rich built-in functionality. Besides the core .NET Framework, the .NET initiative includes protocols (such as the Simple Object Access Protocol, commonly known as SOAP) to provide a new level of software integration over the Internet, via a standard known as Web Services. Although Web Services are important (and are discussed in detail in Chapter 23), the foundation of all .NET-based systems is the .NET Framework. This chapter will look at the .NET Framework from the viewpoint of a Visual Basic developer. Unless you are quite familiar with the Framework already, you should consider this introduction an essential first step in assimilating the information about Visual Basic .NET that will be presented in the rest of this book. The first released product based on the .NET Framework was Visual Studio .NET 2002, which was publicly launched in February 2002, and included version 1.0 of the .NET Framework. Visual Studio .NET 2003 was introduced a year later and included version 1.1 of the .NET Framework. Visual Studio .NET Startup Those of you making the move from COM to .NET will notice that Visual Studio 2005 has one entry for the development environment in the Start menuthere are no separate entries for Visual Basic, Visual C++, or Visual C#. All of the Visual Studio languages share the same integrated development environment (IDE). One of the changes from previous versions of Visual Studio .NET is that the environment can now be customized by project type. When Visual Studio 2005 is started, the window shown in Figure 2-1 is displayed to permit you to configure your custom profile. Unlike previous versions of .NET, where you selected a set of preferences that you would then use for all of your development, Visual Studio 2005 allows you to select either a language-specific or task-specific profile. This book will use screen shots based on the Visual Basic Developer setting.

Figure 2-1 Configuration of the settings is managed through the Import and Export Settings . . . menu option of the Tools menu. This menu option opens a simple wizard, which first saves your current settings and then allows you to select an alternate set of settings. By default, Visual Studio ships with settings for Visual

Basic, Web Development, and C# to name a few, but more importantly by exporting your settings you can create and share your own custom settings files. The Visual Studio settings file is an XML file that allows you to capture all of your Visual Studio configuration settings. This might sound trivial, but its not. The fact is this feature allows for standardization of Visual Studio across different team members. The advantages of a team sharing settings go beyond just using a common look and feel. To illustrate why this can be important, lets look at a simple example of how standardizing a portion of Visual Studio can impact team development. Tracking changes to source code can be made more difficult simply from the way that Visual Basic reformats code layout for readability. Most source control systems track code changes on a per line basis. Taking just the simple example of changing the default tab value associated with the Text Editor and reducing it from four characters to two or three characters can make code more readable and less likely to wrap. Unfortunately, if someone on the team does pick a different value, then as each engineer checks out code and makes modifications, he or she also resets the white space on every line of the source file. Thus, when the source file is checked back in, instead of having the code changes that are easily highlighted, all of the lines where the tabs were adjusted show up as changed and tracking changes becomes more difficult. The solution is to provide a common settings file that defines settings such as the correct tab and layout for Hypertext Markup Language (HTML) elements (to name a few common settings) so that everyone starts from the same baseline. In this way developers who work together produce code that has the same layout. Engineers can then customize other settings that are specific to their view of Visual Studio. Visual Studio .NET Once you have set up your profile, the next step is to create your first project. Selecting File.New Project opens the New Project Dialog window, shown in Figure 2-2. One of the changes in Visual Studio 2005 is that once you have selected a default environment setting, you are presented with a settingspecific project view. For Visual Basic this means that you are presented with Visual Basic project templates by default. A quick note, however: Not all project templates are listed within the New Project dialog. For example, if you want to create a Visual Basic Web site, you need to start that process by creating a new Web site instead of creating a new project. Expanding the top level of the Visual Basic tree, you may notice that this window separates project types into a series of categories. These categories include . WindowsThose projects used to create code that runs as part of the standard .NET Framework. Since such projects can run on any operating system (OS) hosting the framework, the category Windows is something of a throwback. OfficeThe replacement for Visual Studio Tools for Office (VSTO). These are .NET applications that are hosted under Office 2003. Smart DeviceThese 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. DatabaseThis 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. Visual Studio has other categories for projects and you have access to Other development languages and far more project types then we will cover in this one book. For now, you can select a Windows Application project template.

Introducing Visual Basic 2005 and Visual Studio 2005

Figure 2-2 For this example, you can use ProVB.NET as the project name and then click the OK button. Visual Studio then 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 you start customizing any code, lets first look at the elements of this new project. The Solution Explorer Those of you new to .NET but with previous Microsoft development tool experience will find a solution similar to a project group. However, a .NET solution can contain projects of any .NET language and also allows inclusion of the database, testing, and installation projects as part of the overall solution. Before discussing these files in detail, lets take a look at the next step, which is to reveal a few additional details about your project. Click the second button from the left in Solution Explorer to show all of the project files, as shown in Figure 2-3. 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, dont require you to edit them directly. Instead, you can double-click on the My Project entry in the Solution Explorer and open the user interface to adjust your project settings. You do not need to change any of the default settings for this project, but those of you familiar with Visual Studio 2003 should notice many of the new capabilities provided by this window. These include the ability to add and manage your project references. Similar to how a traditional Windows application allows you to reference COM components, .NET allows you to create references to other components (those implemented both with a .NET language and with COM) to extend the capabilities of your application. The bin and obj directories that are shown in this display 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,since the actual translation to binary does not occur until runtime when your application is compiled by the Just in Time Compiler. However, Microsoft continues to use the bin directory as the default output directory for your projects compilation.

Figure 2-3 Additionally, Figure 2-3 shows that the project does not contain an app.config file by default. Most experienced ASP.NET developers are readily familiar with the use of web.config files. App.config files work on the same principal 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 allows your applications to run side by side with another version of your application without the settings from either version impacting the other. Because each version of your application will live in its own directory, its settings will be contained in the directory with it, which enables the different versions to run with unique settings. 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. Youll be customizing this form shortly, but before looking at that, it seems appropriate to look at some of the settings exposed by the My Project element of your new project. My Project Visual Studio displays a vertically tabbed display for editing your project settings. The My Project display shown in Figure 2-4 gives you access to several different aspects of your project. Most, such as Signing, Security, Publishing, and so forth, will be covered in future chapters. For this chapter, it should just be noted that this display makes it easier to carry out several tasks that once required engineers to work outside of the Visual Studio environment. For your first application, notice that you can customize your Assembly name from this screen as well as reset the type of application and object to be referenced when starting your application. Introducing Visual Basic 2005 and Visual Studio 2005

Figure 2-4 In addition, there is a button that will be discussed shortly for changing your Assembly information as well as the ability to define a root namespace for your application classes. Namespaces are covered in more detail in Chapter 9 and can be nested inside other namespaces. This nesting helps to organize classes into a logical structure, which reduces confusion and aids the developer. Just as with COM components, its a good idea to create your own root namespace and then build your custom classes under that root. Similarly, your project already references some system namespaces.

Você também pode gostar