Create a Windows Installer

Products

Purpose

This tutorial is in addition to my tutorial on using the MyODBC Connector, and uses the MyStore database. This tutorial is a step-by-step instruction in creating a Windows Installer for the MyStore Application, which includes the MyODBC Connector as part of the installation. As usual for me, I skip the nice-looking stuff in favor of the fundamentals.

Why?

Visual Studio.NET 2005 comes with a one-click installer which can be very useful, but I do not like it. I find that including anything un-Microsoft (such as the MyODBC Connector) with the installer is difficult. In addition, I find certain defaults difficult to override — such as installing for all users on a computer vice the administrator only.

Initial Steps

This tutorial assumes you have completed the MyODBC Connector Databinding tutorial and have a working version of the MyStore database.

In order to create an installer for the MyStore application, we need several files to include with the installer to ensure they are added to the client computer.

  1. Create a folder for holding the following downloads:
    1. Download Microsoft .NET Framework v2 (dotnetfx.exe) to the folder.
    2. Download Microsoft Data Access Components (MDAC_TYP.exe) to the folder.
    3. Download MySQL Connector/ODBC for Windows (setup.exe) to the folder.
  2. Make sure all downloads are unzipped within the folder.
  3. For simplicity, after download, I rename the MyODBC Setup file (setup.exe) to MyODBC_Setup.exe.
  4. Open the MyStore Solution.
  5. Right-click on the MyStore Solution in the Solution Explorer and select Add –> New Folder.

  6. Name the new folder support.

  7. Right-click on the support folder and select Add –> Existing Item…

  8. Browse to the folder you created in the Initial Steps and select Executable Files as the Files of type.

  9. Select the files downloaded in the Initial Steps and select Add. The Solution Browser will show these files as being added to the solution.

  10. From the Project menu, select MyStore Properties.

  11. Within the Application tab, select Assembly Information…

  12. There is nothing here to change at this point, but on successive builds, you may want to change the Assembly Version and File Version fields in order to allow newer versions of the program to overwrite previous versions when re-installed on a client computer.

  13. Select OK.
  14. From the Build menu, select Clean Solution to remove unnecessary files.

  15. Select Build Solution to ensure the most current content is reflected in the output files (within the bin/release folder).

Create the Windows Installer Project

  1. Select File –> New Project….
  2. In the New Project dialog box, select Setup and Deployment and select the Setup Wizard icon.

  3. The Name determines the name of the folder as well as the name of the install file. In this case, I am using MyStore Application.
  4. From the Solution list, select Add to Solution. The Location auto-fills and the other selections become disabled.
  5. Select OK. The Setup Project Wizard appears.

  6. Select Next >.

  7. Select to Create a setup for a Windows application and select Next >.

  8. Select the Primary output from MyStore and select Next >.

  9. This is a good place to add icon files, executable files, or library files needed by the installation. We could add the files we downloaded earlier here, but we will do it later to show how to add files to the project. Select Next >.

  10. Select Finish >. The Solution Explorer will show the new project within the MyStore solution.

  11. With the installation solution highlighted, move to the Properties window.

  12. A few of these settings have more meaning down the road:
    1. DetectNewerInstalledVersions = True: Allows the installer to detect if a newer version of the application is already installed. This uses the Version information entered earlier in the MyStore Properties.
    2. InstallAllUsers = True: This is False by default. It only determines the default setting in the installer, which the user can change, but I am assuming here that this application will be installed on a multi-user computer for all users.
    3. Manufacturer = something other than Default Company Name: This seemingly useless field determines the default folder name the application will install to. Default Company Name makes for a pretty ugly folder name.
    4. RemovePreviousVersions = True: This is False by default. Making it True allows the installer to remove previous versions of the program. Again, this uses the Version information entered earlier.
    5. Title: Specifies the title of the installer. Don’t name it setup, as the installer creates a loader program called setup, and it may confuse the user.
    6. Version: It does not seem as the Installer uses this in looking for older or newer versions, but I make it match the Version information I entered in earlier anyway.

  13. In the File System window, open the Application Folder by clicking on it.

  14. Right-click within the files pane and select Add –> Folder.

  15. Name the new folder support.

  16. Right-click in the file pane of the support folder and select Add –> File….

  17. Browse to the MyStore\Mystore\support directory and select the files you downloaded earlier.

  18. Select Open. The files will be added to the Installer Project’s support folder.

  19. Right-click the Installer Project in the Solution Explorer and select View –> Launch Conditions.

  20. By default, the .NET Framework is already a Launch Condition of the installer. In other words, the .NET Framework must be installed before the application is installed.

  21. If it is not, by default, it will be downloaded from the Internet. Since we have included the dotnetfx.exe file with our project, we can re-direct the installer to load it from the support directory.
  22. With the .NET Framework selected, change the InstallUrl property in the Properties window to support\dotnetfx.exe.

  23. Microsoft Data Access Components are required for .NET applications to run. MDAC 2.8 (the latest version) is automatically installed with Windows XP SP2, but needs to be installed on previous versions of Windows. We can make the Installer check for the MDAC version and install it if necessary.
  24. This article on MSDN provides the instructions for adding MDAC to the Launch Conditions. The following screenshots show the final result.

  25. As with dotnetfx.exe, notice that I changed the InstallUrl to support\mdac_typ.exe.
  26. Right-click the Installer Project in the Solution Explorer and select View –> Custom Actions.

  27. In the Custom Actions window, right-click the Commit folder and select Add Custom Action….

  28. In the Select Item in Project window, drill down to the Application Folder\support folder to find the MyODBC_Setup.exe file.

  29. The MyODBC_Setup program will be added to the project, and will run once the application installs successfully.

Create a Shortcut in the Programs Menu

  1. Right-click the User’s Programs Menu in the File System window and select Add –> Folder.

  2. Name the folder VBMySQL. This name determines the name of the folder within the Programs menu in which the shortcut will be placed.

  3. Right-click the Primary output from MyStore (Active) within the Application Folder and select Create Shortcut to Primary output from Mystore (Active).

  4. Name the new shortcut MyStore.

  5. Drag the MyStore shortcut to the VBMySQL folder.

  6. In the Properties window of the MyStore shortcut, you have the ability to add a custom icon. Any custom icons must be saved in the Application Folder before they can be selected from the Property window.

  7. If you want to add a shortcut on the user’s desktop, follow the same procedures above for the User’s Desktop folder.

Build the Installer

  1. With the MyStore Installer project selected in the Solution Explorer, select Clean Solution, then Build Solution from the Build menu.

  2. Once again, this deletes unnecessary files from the solution, and ensures the most current content is reflected in the output files (within the MyStore\MyStore\bin\release folder).
  3. With the MyStore Installer project selected in the Solution Explorer, select Build MyStore Application from the Build menu.

  4. This step (which takes a few minutes) creates the installation files.
  5. Close Visual Studio when the Build succeeds.
  6. You will find the installation files in the MyStore\MyStore Application\Release folder.

  7. Copy these files to the installation medium of your choice.

Summary

This tutorial demonstrated how to build an installer for a VB.NET application using Visual Studio that includes the MyODBC Connector.