Upgrading Project Groups

Upgrading Project Groups

The Upgrade Wizard upgrades only projects. But what about project groups? In Visual Basic 6, you could create a project group that contained several projects. When you pressed F5, all of the projects in the group were compiled together, and the debugger could step from code in one project into code in another. Project groups are useful when one project references another.

The Visual Basic .NET equivalent of a project group is a solution. Each solution contains one or more projects. As in Visual Basic 6, they are all compiled together when you press F5, projects can reference other projects in the same group, and the debugger can step from code in one project into code in another. Not all projects in a solution have to be Visual Basic .NET projects. A solution can contain projects written in different languages, such as Visual Basic .NET, C#, and Visual C++.

To upgrade a project group to Visual Basic .NET, you need to upgrade one project at a time, starting with the most downstream project and working your way up the dependency hierarchy. For example, if your project group contains an EXE project that references a DLL project, you should upgrade the EXE first, followed by the DLL. Let s walk through an example to see how this is done. First we will create a project group in Visual Basic 6, and then we will upgrade it one project at a time to Visual Basic .NET. Our project group will be simple: it will show Hello World in a message box when you click a CommandButton on a form.

  1. Open the project you created earlier in Visual Basic 6 (prjFirst Upgrade.vbp). Add a new DLL project by choosing Add Project from the File menu and selecting ActiveX DLL from the Add Project dialog box. A DLL project called Project1 is added to the Project Explorer. The two projects are now part of a project group.

  2. Visual Basic 6 automatically adds a new class in Project1, Class1. Add the following code to the class:

    Sub sayHelloWorld()    MsgBox "Hello World" End Sub

  3. Close the Class1 Code Editor, and save all the files by choosing Save Project Group from the File menu. Make sure you save all the files in the same directory as the first project. Accept the default filenames; the project group will be called Group1.vbp, and the new project will be called Project1.vbp.

  4. Now we will make prjFirstUpgrade reference Project1. Select prjFirstUpgrade in the Project Explorer, and choose References from the Project menu. In the References dialog box, select Project1, and click OK. Figure 5-12 shows the References dialog box.

    Figure 5-12

    References dialog box.

  5. Let s use the Project1 Class1 from prjFirstUpgrade. Open prjFirst Upgrade.Form1 in the Form window, and double-click the Command1 CommandButton to edit the Click event code. Change the Click event code to the following:

    Private Sub Command1_Click()    Dim c As New Class1    c.sayHelloWorld End Sub

    After you ve added this code, the project group will look like Figure 5-13.

    Figure 5-13

    Project group in Visual Basic 6.

  6. Let s test it out. Press F5 to run the project group. When you click the CommandButton Command1, a message box pops up with the text Hello World.

  7. We ll do two more things before we upgrade the group. First, save the group by choosing Save Project Group from the File menu. Next, compile the group by choosing Make Project Group from the File menu. Compiling is necessary because the Upgrade Wizard checks the timestamp of the Project1 project against the timestamp of the Project1 DLL. If the project file is newer than the DLL, the wizard assumes that the DLL is out of date and asks you to recompile it.

Now that we ve created a project group in Visual Basic 6, let s upgrade it to Visual Basic .NET. First we ll upgrade the EXE prjFirstUpgrade. Then we ll upgrade the DLL Project1. Finally, we ll change prjFirstUpgrade so that it references the upgraded Project1.

  1. Start Visual Basic .NET, and upgrade prjFirstUpgrade. (If you need a recap on how to upgrade a project, see the section Upgrade Walkthrough earlier in this chapter.) You won t need to make any modifications to the upgraded code, since we replaced Timer.Interval = 0 with code that shows a message box.

  2. Now let s upgrade Project1 to be part of this solution. In Visual Basic .NET, from the File menu choose Add Project and then Existing Project. This opens the Add Existing Project dialog box. Select Project1.vbp and click the Open button to upgrade Project1. Accept the default upgrade options, as you did with prjFirstUpgrade.

  3. Is that all there is to do? Not quite. The project prjFirstUpgrade still references the Visual Basic 6 version of Project1. We need to delete the reference to the Visual Basic 6 Project1 DLL and add a reference to the upgraded Visual Basic .NET Project1. First let s remove the reference. Expand the prjFirstUpgrade references node and remove the reference Interop.Project1_1_1 by right-clicking it and selecting Remove. Note that in your project, this reference might be called something slightly different. Look for the reference with Project1 in the name. For information on adding and removing references, see Chapter 6.

  4. Add a reference to the upgraded Project1 by right-clicking References, selecting Add Reference, and then selecting Project1 in the Add Reference dialog box.

  5. That s it! Press F5 to run the solution. When you click the Command1 button, you will see a message box, as shown in Figure 5-14.

    Figure 5-14

    Upgraded project group.

You now know the basic procedure for upgrading project groups. If your Visual Basic 6 project group contains many projects, you simply repeat these steps for every project in the group. Start with the most downstream project, and work your way up the dependency hierarchy.



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

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