Export (0) Print
Expand All
Around the World with Visual Basic
Asynchronous Method Execution Using Delegates
Building a Progress Bar that Doesn't Progress
Calling All Operators
Create a Graphical Editor Using RichTextBox and GDI+
Creating A Breadcrumb Control
Creating a Five-Star Rating Control
Creating and Managing Secondary Threads
Data Binding Radio Buttons to a List
Deploying Assemblies
Designing With Custom Attributes
Digital Grandma
Doing Async the Easy Way
Extracting Data from .NET Assemblies
Implementing Callbacks with a Multicast Delegate
Naming and Building Assemblies in Visual Basic .NET
Programming Events of the Framework Class Libraries
Programming I/O with Streams in Visual Basic .NET
Reflection in Visual Basic .NET
Remembering User Information in Visual Basic .NET
Advanced Basics: Revisiting Operator Overloading
Scaling Up: The Very Busy Background Compiler
Synchronizing Multiple Windows Forms
Thread Synchronization
Updating the UI from a Secondary Thread
Using Inheritance in the .NET World
Using the ReaderWriterLock Class
Visual Basic: Simplify Common Tasks by Customizing the My Namespace
What's My IP Address?
Windows Forms Controls: Z-order and Copying Collections
Expand Minimize

Deploying Hybrid Visual Basic 6.0 / Visual Basic .NET Applications

Visual Studio .NET 2003
 

Steve Hoag
Visual Studio Team
Microsoft Corporation

July 2002

Summary: This paper demonstrates how to deploy applications that contain both Visual Basic 6.0 and Visual Basic .NET components. (7 printed pages)

Contents

Introduction
Deploying a Visual Basic .NET Application That Contains Visual Basic 6.0 Components
Deploying a Visual Basic 6.0 Application That Uses .NET Components
Conclusion

Introduction

As you move forward from Microsoft® Visual Basic 6.0 to Visual Basic .NET, you will likely face situations involving the deployment of hybrid applications — that is, applications utilizing components created in both versions of the language.

COM interoperability in Visual Basic .NET allows .NET applications to use COM components created with Visual Basic 6.0; it also allows you to create .NET components that can be called by Visual Basic 6.0 applications. A discussion of COM interoperability is beyond the scope of this article. For more information about COM interoperability, see Introduction to COM Interop.

Perhaps you have a Visual Basic 6.0 application that needs enhancement. Rather than upgrading the application, you might decide to create a component in Visual Basic .NET. In other cases, you may have components created with Visual Basic 6.0 that are still used by several applications. Rather than creating a new component in Visual Basic .NET, you might want to use the existing COM component.

In either case, you will want to deploy your Visual Basic 6.0 and Visual Basic .NET components together. This article will walk you through the process of deploying a hybrid application using the deployment tools in Visual Basic .NET.

Deploying a Visual Basic .NET Application That Contains Visual Basic 6.0 Components

Deploying an application that contains Visual Basic 6.0 COM components is similar to deploying any other Visual Basic .NET application. The only difference is the requirement to include the Visual Basic 6.0 runtime merge module. The merge module is used to automatically install the Visual Basic 6.0 runtime files if they are not present on a target computer; the runtime files are required by the COM components.

COM components referenced in a Visual Basic .NET application are automatically added to a setup project as part of the application project's outputs. Windows Installer takes care of registering the COM components during installation.

The following are the steps required to deploy your Visual Basic .NET application along with your COM components.

Add a Setup Project to the Solution

The first step is to add a Setup project to the solution that contains your Visual Basic .NET application. This will create an installer for your application.

To add a Setup project

  1. On the File menu, point to Add Project, then click New Project.
  2. In the Add Project dialog box, select the Setup and Deployment Projects node, then click Setup Project.
  3. In the Name field, enter a name for your setup project.
    Tip   The project name is also used as the ProductName property for the project; this property is used to display the name to users during installation. Choose a meaningful name for your project — for example, if your application is named "My Application", name your project "My Application Installer".
  4. Click OK to continue.

In the next step you will associate your application project with the setup project by adding the project outputs.

Add the Project Outputs to the Setup Project

Project outputs are the files created when you build your application. For a Windows® application, the output would be the .exe file for your application; depending on your build settings, other files might be included as well.

To add project outputs

  1. In the File System Editor, click the Application Folder.
  2. On the Action menu, point to Add, and then click Project Output.
  3. In the Add Project Output Group dialog box, click your application project, then click Primary output.

    A warning dialog box will be displayed noting that the dependencies for your COM components cannot be determined. In most cases, you can ignore this warning; however, if your COM components have dependencies on other COM components, you will need to add these manually.

  4. If you need to add dependencies for your COM components, do the following:
    1. In the File System Editor, click the Application Folder.
    2. On the Action menu, point to Add, then click File.
    3. In the Add Files dialog box, browse to the location of your dependent .dll, click the .dll file, and then click OK.
  5. Click OK to continue.

In the next step, you will add a merge module for the Visual Basic 6.0 runtime.

Add the Visual Basic 6.0 Merge Module

The Visual Basic 6.0 merge module (Msvbvm60.msm) contains the runtime files required by your Visual Basic 6.0 COM components. This will automatically install the runtime files if they are not already installed on a target computer.

The merge module was included with the Visual Studio® Installer add-in for Visual Studio 6.0. By default, it is installed in the \Program Files\Common\Merge Modules directory. The merge module can also be downloaded from the Microsoft Web site (http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/mmoverview.asp).

To add the merge module

  1. In Solution Explorer, click the Setup project.
  2. On the Project menu, point to Add, then click Merge Module.
  3. In the Add Modules dialog box, click the Msvbvm60.msm merge module, and then click OK.

    The merge module will be added to the setup project in Solution Explorer.

In the final step, you will build the installer and deploy the application.

Build the Installer

When you build your setup file, several files are built and placed in a directory beneath your setup project. These include:

  • Windows Installer (.msi) file for your application
  • two .exe files that contain the Windows Installer bootstrapper used to install Windows Installer if necessary
  • Setup.ini file
  • Setup.msi file

All of these files need to be distributed; the user will run the Setup.msi file to install the application.

To build the installer

  1. On the Build menu, click Build SetupProjectName where SetupProjectName is the name of your setup project.
  2. In Windows Explorer, browse to your setup project directory and find the built installer. The default path will be \documents and settings\yourloginname\setupprojectname\project configuration\setupprojectname.msi. The default project configuration is Debug.
  3. Copy all of the files from this directory to your distribution media or to a network location.

    When a user runs the Setup.msi file, the application will be installed, all COM components will be registered, and if necessary, the runtime files will be installed.

In the next section, we'll cover the opposite situation — deploying a Visual Basic 6.0 application that uses .NET components.

Deploying a Visual Basic 6.0 Application That Uses .NET Components

Although Visual Basic 6.0 projects cannot be part of a Visual Studio .NET solution, you can still use the deployment tools in Visual Studio .NET to deploy your compiled Visual Basic 6.0 applications. If the Visual Basic 6.0 application uses .NET components, the process is similar to the preceding example, with a couple of exceptions. You will need to:

  • Create merge modules for the components.
  • Implement COM registration.

The first step is to create a setup project in the solution that contains the .NET component, as described in Add a Setup Project to the Solution above. Next you will add the Visual Basic 6.0 application to the setup project.

Add the Visual Basic 6.0 Application to the Setup Project

Visual Basic 6.0 projects are not part of the solution, so you cannot add the project outputs as in the previous example. Instead, you will need to add the built executable (.exe) file for the Visual Basic 6.0 application as a file.

To add a file

  1. In the File System Editor, click the Application Folder.
  2. On the Action menu, point to Add, and then click File.
  3. In the Add Files dialog box, browse and select the .exe file for your Visual Basic 6.0 application, then click Open.
    Note   The setup project will not be able to automatically detect dependencies for the Visual Basic 6.0 application; you will need to manually add any dependent files. You can use a tool such the Dependency Walker (depends.exe) that is included in the Visual Studio .NET Tools directory to determine the dependencies for your application.

In the next step, you will create a merge module for your .NET component.

Create a Merge Module for the .NET Component

Merge modules are used to package components in a way that they can be shared between deployment projects while maintaining version integrity. You should create a separate merge module for each component, and create a new merge module for each subsequent version of that component.

Note   Although it is possible to add a component directly to a deployment project, it is highly recommended that you use a merge module. If your component is not shared between applications and you are sure that it will never be shared in the future, you can add it to the application folder.

To create a merge module

  1. On the File menu, point to Add Project, then click New Project.
  2. In the Add Project dialog box, click the Setup and Deployment Projects node, then click Merge Module Project.
  3. In the Name field, enter a name for your project, and then click OK to continue.
  4. In the File System Editor, click the Module Retargetable Folder.

    The Module Retargetable Folder is a special folder that allows the consuming setup project to specify where the component will be installed. For more information, see Retargetable Merge Modules.

  5. On the Action menu, point to Add, then click Project Output.
  6. In the Add Project Output Group dialog box, click your component project, then click Primary output.
  7. Click OK to continue.
  8. On the Build menu, click Build ProjectName where ProjectName is the name of your Merge Module project.

The next step is to add COM registration for your component.

Add COM Registration for the .NET Component

In order to be visible to the Visual Basic 6.0 application, your component must be registered as a COM component during installation. This is done using the Register property for the component's project output group.

To add COM registration

  1. In the Name column of the File System Editor, click Primary output from ProjectName, where ProjectName is your component project.
  2. In the Properties window, click the Register property and change it to vsdrpCOM.

The next step is to add the merge module to your setup project.

Add the Merge Module to the Setup Project

Adding a merge module is similar to adding the project outputs of an application project in the previous example. The difference is deciding where to install it. If the component is not shared, you should put it in the application folder; if it is shared, you should put it in the global assembly cache folder.

Note   In order to install a component in the global assembly cache it must be a strong-named assembly. For more information, see Creating and Using Strong-Named Assemblies.

To add the merge module for a shared component

  1. In Solution Explorer, click the setup project.
  2. On the View menu, point to Editor, then click File System.
  3. In the File System Editor, select the File System on Target Machine node.
  4. On the Action menu, point to Add Special Folder, then click Global Assembly Cache Folder.
  5. In Solution Explorer, click the Setup project.
  6. On the Project menu, point to Add, then click Merge Module.
  7. In the Add Modules dialog box, browse to the location of the merge module that you created in the earlier step and select it.

    The default path will be \documents and settings\yourloginname\mergemoduleprojectname\project configuration\mergemoduleprojectname.msm. The default project configuration is Debug.

  8. Click Open to continue. The merge module will be added to the Setup project in Solution Explorer.
  9. Select the merge module. In the Properties window, select (MergeModuleProperties) and expand the node.
  10. Select the Module Retargetable Folder property, then select (Browse…) from the drop-down list.
  11. In the Select Folder dialog box, select Global Assembly Cache Folder.
  12. Click OK to continue.

To add the merge module for an unshared component

  1. In Solution Explorer, click the setup project.
  2. On the Project menu, point to Add, then click Merge Module.
  3. In the Add Modules dialog box, browse to the location of the merge module that you created in the earlier step and select it.

    The default path will be \documents and settings\yourloginname\mergemoduleprojectname\project configuration\mergemoduleprojectname.msm. The default project configuration is Debug.

  4. Click Open to continue. The Merge Module will be added to the Setup project in Solution Explorer.

The final steps are to add the Visual basic 6.0 merge module as described above in Add the Visual Basic 6.0 Merge Module, and to build and deploy your installer, as described above in Build the Installer.

Conclusion

Although slightly more complicated than deploying a standard Visual Basic .NET application, deploying a hybrid application is still relatively easy. In addition to the steps outlined in this article, you may want to enhance your installer by utilizing the capabilities of Visual Studio deployment, including customizing the user interface, writing to the registry, registering file types, or adding launch conditions and custom actions.

See Also

Deploying Applications and Components | Deployment Walkthroughs | Deployment Changes in Visual Basic .NET

Show:
© 2014 Microsoft