Creating a Project

Team-Fly    

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

Creating a Project

To pay homage to our forebears, we will examine the revised project management facilities and create the notorious "Hello World" application as a console application. (For more information on Project Templates, refer to the section later in this chapter, "An Overview of Project Templates.")

By now you will have configured your profile to using Visual Basic settings. At this point choose File, New, Project in Visual Studio .NET. The New Project window lists project types; select the Visual Basic Projects folder. On the right side of the New Project dialog box, select the Console Application template. (You may have to scroll the Templates window a little to find it.)

At this point, you will be presented with a default project name, most likely ConsoleApplication1, and a Location. The default location will be a subdirectory of where Visual Studio .NET was installed. Change the default name to HelloWorld, and select the location where you want the project to reside. It's important to note at this point that Visual Studio .NET uses a hierarchical source file structure; keep in mind that creating a new project will create several folders and files.

Tip

In Visual Studio .NET, you can close a solution without opening a new solution by choosing File, Close Solution. A solution is the term used to refer to your project.


After you've indicated the project name and location, click OK to create the console application. What Visual Studio .NET will do is create a solution, a .sln file, and other files that constitute a blank console project.

Project Files and Directories

A flat project topology isn't a very good way to organize project files, and all we have in software development is organization. Housekeeping is critical to managing intellectual property such as source code. Microsoft has acknowledged the value of organization by refining Studio to create a hierarchical solution structure for Visual Basic projects. (Refer to the "Solution Explorer" section later in this chapter for more information on managing project files.)

At the beginning of the section, we created the HelloWorld console solution. Visual Studio created a subfolder with the same name as the project, bin and obj subfolders , for storing the application files and intermediate files respectively, and the solution and source code files in the HelloWorld folder. If you look in the obj folder, you will see that Studio is distinguishing between DEBUG intermediate files and release files. (See "Adding Your Project to Source Control" for more on build management.)

In the HelloWorld folder, you will find AssemblyInfo.vb, HelloWorld.sln, HelloWorld.suo, HelloWorld.vbproj, HelloWorld.vbproj. user , and Module1.vb. See Table 1.1 for an overview of file extensions in the HelloWorld solution and their use.

Table 1.1. VB .NET File Extensions in Visual Studio
File Extension Description
.sln Solution file, which is similar to the VB6 group file and contains one or more projects
.suo Contains user options for a solution
.vbproj Represents a single project, or all of the files that are used to create an assembly
.user Contains project-level user options
.vb Contains source code

There are several other project types and each comes replete with incumbent file extensions. For example, your macros are stored in files with a .vsmacros extension (see Chapter 4).

All that remains in our console application is AssemblyInfo.vb and Module1.vb. The AssemblyInfo.vb file contains extra information, or metadata, about your application. For now, leave the AssemblyInfo.vb file alone. (For more on the AssemblyInfo.vb file and metadata, read Chapter 12, which explains metadata.)

Module1.vb (named so by default) is the primary file of interest for our console application. First you will note that module files no longer have a .bas extension. The module file for the console application contains some special text, as shown in Listing 1.1.

Listing 1.1 A .vb File in the HelloWorld console application
 Module Module1 Sub Main() End Sub End Module 

The lines containing Module Module1 and End Module define the boundary of the module source code. In .NET, more than one entity can be defined per file; therefore, types are delimited using a block statement indicating the beginning and ending of a new type. Because a console application was requested , an empty SubMain was added to the module. Sub Main is the entry point for a console application. The General view of the property pages indicates that Module1 is the Startup object, as shown in Figure 1.1. To view the property pages, open the Solution Explorer by pressing Ctrl+Alt+L and click the HelloWorld project (or whichever project you are working on). Choose Project, Properties. (The Project menu is context-sensitive; the menu items change depending on the element selected in the Solution Explorer.)

Figure 1.1. The General view of the property pages, indicating that HelloWorld is a console application that starts with Module1.

graphics/01fig01.jpg

This is our first application so we will keep it simple. Revise the code from Listing 1.1 to write "Hello World" to the console, as shown in Listing 1.2.

Listing 1.2 Homage to those who came before
 Module Module1 Sub Main() System.Console.WriteLine("Hello World!") End Sub End Module 

The only revision from Listing 1.1 to Listing 1.2 is the addition of the System.Console.WriteLine("Hello World!") line. Press the shortcut key for the Debug, Step Into menu a couple of times to step through the demo. (If you are using the VB6 profile, as we will be in this book, the shortcut is F8; the default profile uses F10 for debug stepping.) You will notice a command window open that displays the text Hello World!.

This brief fragment introduces a lot of new things. First, notice that we are using parentheses without the Call keyword. In VB .NET we don't need the Call, but we do need parentheses. Also, notice the use of the System.Console namespace. Namespaces have to do with organizing classes to avoid global name conflicts. That is to help prevent you and me from naming two classes identically. Visual Basic .NET doesn't require you to indicate explicitly that you want to create an executable. If you step through the program or run it by pressing F5, Studio compiles an executable and places it in the bin folder. After you step through the code in Listing 1.2, HelloWorld.exe resides in the bin project subfolder. To run the console application outside the IDE, click Start, Run in Windows and type cmd in the Run dialog box (for Windows NT/2000). Change folders to the bin location containing your project's executable, type the name of the executable, and then press Enter.

Adding Your Project to Source Control

Creating intellectual property is what software development is about. Microsoft started with some handwritten notes on porting B.A.S.I.C. from a PDP-11 to a version for the Altair-MIPS. At one time or another, the handwritten notes were transcribed into a book. If anyone had known that this chicken-scratched version of Beginners All Purpose Symbolic Instruction Code (B.A.S.I.C.) would eventually be worth half a trillion dollars, they would have locked it in the vault at the intersection of Gold Vault Road and Bullion Boulevard at Fort Knox.

Note

All intellectual property should be archived. This includes manuscripts, graphic art, legal documents, and, of course, source code. Version control tools are easy and affordable enough for anyone to use.


When you are writing software, you are creating intellectual property that has value to someone, and as property it should be protected. Version control applications like Visual SourceSafe perform this task. Visual SourceSafe stores the code in a database and allows you and others to check files in and out between revisions. Visual SourceSafe tracks revisions, allowing you to access any version of the code at any time.

If you begin a project with source control, you will find it significantly easier to revise and customize your code with impunity. The source control tool allows you to restore your code easily to any prior state, if used properly. Using SourceSafe with Visual Studio .NET is easier than ever.

There are a few prerequisites to adding your solution to Visual SourceSafe. You will need Visual SourceSafe installed. You will need to create a database and have the administrator create a user name and password for you. If a SourceSafe database is configured, from Visual Studio .NET, choose File, Source Control, Add Solution to Source Control. You will be prompted to enter your user name, password, and the name of your SourceSafe database.

Note

You can add code to make your application an Automation controller for SourceSafe too. Suppose you are writing a program for designing marketing media. You want to allow the creative marketing people to archive their information. Instead of re-creating a source management tool, add some code to control SourceSafe and encourage your customers to buy SourceSafe.


Why does all this work so well? SourceSafe is accessible from Studio because someone had the foresight to make SourceSafe an Automation server application. This means that Automation controller applications can be written to manage SourceSafe externally. Visual Studio .NET is a SourceSafe automation controller.

Configuring SourceSafe

The Source Control view of the Options dialog box enables you to configure source control information. For example, I navigated to the SCC Provider subview, and Visual Studio .NET had already retrieved information, including my user name. When I actually checked in the HelloWorld solution, it also grabbed the information about the database to use and updated the Source Control view appropriately.

Default information, including your default SourceSafe database, is stored in configuration files and SourceSafe can obtain this information. Whatever SourceSafe makes available via its Automation interface can also be requested from Automation controllers. Hence Visual Studio .NET can obtain necessary configuration information from SourceSafe, and allow you to modify it via the Source Control view (see Figure 1.2).

Figure 1.2. Configure source control to get everything when you open a solution and check in everything when you are finished coding by checking the options as shown.

graphics/01fig02.jpg

In the General subview of the property pages, you can check the first two check boxes (see Figure 1.2). These two options will ensure that the most recent files are retrieved from source control when you open a solution and that everything is checked in when you close the solution.

Source Control Capabilities

After you incorporate Source Control into your solution, many of the options available directly from SourceSafe are incorporated into the Source Control submenu (File, Source Control). You can choose to get, share, check in, check out, or compare files, and view file histories.

SourceSafe is a separate product, so covering it in detail would require another book. However, there are some things that you can do to get the most out of SourceSafe or any Source Control product. First, use source control from day one. Second, don't controvert the role of source control. It's the tool's responsibility to track versions; making subprojects to track separate versions of source gets in the way of the tool. Don't do it. Finally, use sharing, branching, pinning, and labelingavailable in many source control productsto manage your code effectively.

Appointing a librarian to manage the source product is a good idea. A librarian can ensure that source control is being used properly, help arrange training for novices, and facilitate build management. For very small teams , the librarian may also be assigned other duties .


Team-Fly    
Top
 


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

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