Create a Windows Installer

December 13th, 2006 Leave a comment Go to comments

Part of the MyODBC Connector Databinding Tutorial

Matthew R. King
mking56@comcast.net

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. wi1.JPG

  7. Name the new folder support.
  8. wi2.JPG

  9. Right-click on the support folder and select Add –> Existing Item…
  10. wi3.JPG

  11. Browse to the folder you created in the Initial Steps and select Executable Files as the Files of type.
  12. wi4.JPG

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

  15. From the Project menu, select MyStore Properties.
  16. w5a.JPG

  17. Within the Application tab, select Assembly Information…
  18. wi5b.JPG

  19. 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.
  20. wi5c.JPG

  21. Select OK.
  22. From the Build menu, select Clean Solution to remove unnecessary files.
  23. wi5d.JPG

  24. 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. wi6.JPG

  4. 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.
  5. From the Solution list, select Add to Solution. The Location auto-fills and the other selections become disabled.
  6. Select OK. The Setup Project Wizard appears.
  7. wi7.JPG

  8. Select Next >.
  9. wi8.JPG

  10. Select to Create a setup for a Windows application and select Next >.
  11. wi9.JPG

  12. Select the Primary output from MyStore and select Next >.
  13. wi10.JPG

  14. 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 >.
  15. wi11.JPG

  16. Select Finish >. The Solution Explorer will show the new project within the MyStore solution.
  17. wi12.JPG

  18. With the installation solution highlighted, move to the Properties window.
  19. wi13.JPG

  20. 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.
  21. In the File System window, open the Application Folder by clicking on it.
  22. wi14.JPG

  23. Right-click within the files pane and select Add –> Folder.
  24. wi15.JPG

  25. Name the new folder support.
  26. wi16.JPG

  27. Right-click in the file pane of the support folder and select Add –> File….
  28. wi17.JPG

  29. Browse to the MyStore\Mystore\support directory and select the files you downloaded earlier.
  30. wi18.JPG

  31. Select Open. The files will be added to the Installer Project’s support folder.
  32. wi19.JPG

  33. Right-click the Installer Project in the Solution Explorer and select View –> Launch Conditions.
  34. wi20.JPG

  35. 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.
  36. wi21.JPG

  37. 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.
  38. With the .NET Framework selected, change the InstallUrl property in the Properties window to support\dotnetfx.exe.
  39. wi22.JPG

  40. 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.
  41. This article on MSDN provides the instructions for adding MDAC to the Launch Conditions. The following screenshots show the final result.
  42. wi23.JPG wi24.JPG

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

  46. In the Custom Actions window, right-click the Commit folder and select Add Custom Action….
  47. wi26.JPG

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

  50. The MyODBC_Setup program will be added to the project, and will run once the application installs successfully.
  51. wi28.JPG

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. wi29.JPG

  3. Name the folder VBMySQL. This name determines the name of the folder within the Programs menu in which the shortcut will be placed.
  4. wi30.JPG

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

  7. Name the new shortcut MyStore.
  8. wi32.JPG

  9. Drag the MyStore shortcut to the VBMySQL folder.
  10. wi33.JPG

  11. 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.
  12. wi34.JPG

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

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. wi37.JPG

  3. 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).
  4. With the MyStore Installer project selected in the Solution Explorer, select Build MyStore Application from the Build menu.
  5. wi36.JPG

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

  10. 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.

  1. Saurabh
    January 8th, 2009 at 20:32 | #1

    You saved me sir.Brilliant stuff.

  2. tuhin
    January 12th, 2009 at 02:14 | #2

    Thank You!. I didn’t try the full step. but i hope it will work.
    Please!!!!! i have an question?
    1. Is it possible to setup mysql databse automatically or Silent Setup

  3. April 11th, 2009 at 17:23 | #3

    Tuhin,

    I tried to research how to add a mysql database with a VB installer – but I could not find it. I may have given up a little easy, however. The applications I have developed are multi-user – one computer acts as the mysql server and the application is installed on all other computers to access it. Unfortunately, this requires the end-user to install mysql, setup the database, and configure access. I provide instructions and scripts, but it is still a hassle for the end-user.

    This approach does have one benefit, however – I don’t have to be concerned about licensing through mysql or violating the openGL license because I don’t bundle mysql with my application.

  4. assia
    September 24th, 2009 at 16:22 | #4

    thank you for your information

    but I want to use mysql without install

    can you help

  5. Locci
    October 24th, 2009 at 17:40 | #5

    You are a guru!

    I am reall learning a lot from these tutorials.
    Please provide me a step by step program of MyStore application. I want to go through it and and in future design my project.

    Thanks!

  6. Locci
    October 24th, 2009 at 17:42 | #6

    I am also requesting for information on how I can develop the Help System for my application!

  7. October 25th, 2009 at 16:00 | #7

    Locci,

    You can find the step-by-step instructions on this site at http://www.vbmysql.com/articles/vbnet-mysql/myodbc-connector.
    I also have the complete, and updated tutorials on my own business site: http://www.emgessoft.com.
    Here is a site for designing Help Systems in VB applications: http://msdn.microsoft.com/en-us/library/ms670134(VS.85).aspx.

  8. October 11th, 2010 at 02:17 | #8

    It Boggles my mind how people live well beyond their means, to either up stage their Family, Friends or Coworkers. No one forces you to run up Credit Card Debt, Student Loans or Car Loans that runs into the ten’s, if not the hundred’s of thousands of dollars. Live within or below your income. Bankruptcy is nothing more than THEFT.

  1. No trackbacks yet.