Article source code: installer.zip
Sooner or later you want to get your stuff on a different machine. It's a pretty simple thing - if you know how to do it. If you don't, you might catch yourself head-banging. I mean, not to the rhythm of heavy metal; it's more like having some "bloody" spots on the wall - and on your shoulders something that once was called a head.
The first time I wanted to make an installer, I used the extraordinarily bad help system. Yes, I know, it's the second time I've grumbled about this. But hey, they could have used the time to write something helpful. Every time I press the F1 key, a nightmare begins. I sometimes even wonder what the F might stand for; but I don't think I have to go into details here.
If you have hard coded paths, the installer does not guarantee that your program will work on a different computer the way it works on yours. There is actually a great chance for things to go wrong, like for example, if a user installs your program in a different directory, like F:\ - c'mon, it really seems to be an omen.
A good way to work around this problem is to use "Application.StartupPath" in your code. The startup path is the folder where the .exe of your program is. During development, the bin folder is the application startup path. All files you want the program to deal with must be there. I have included a sample application that deals with this issue. It is certainly a good idea to look at the code.
The Making of "Setup"
When you open the bin folder of the provided sample program, you will see the three items as shown in Figure 01. The "point2" is a custom cursor and must be included in this folder.
Go back to the "Custom Cursor" folder. This should look like Figure 02.
Double click the solution to open it. From the file menu, point to "Add Project" and click "New Project" on the fly-out menu as Figure 03 indicates.
In the "Add New Project" window, choose "Setup and Deployment Projects" in the left pane and rename it to something appropriate. If you name it "Custom Cursor", you will receive an error message because it's already the name of the project. Since the name must be unique, I usually add the version number. In this case, it could be "Custom Cursor (v. 188.8.131.52)". I named this one "Installer Sample" as you can see in Figure 04. It is also the name that will appear later in the Add/Remove Programs window in the Control Panel. Click "OK" to open the deployment project.
When the project is open, the window should look like Figure 05.
Right click the "Application Folder" in the "File System (Installer Sample)", point to "Add" and then click "Folder" in the fly-out menu as Figure 06 indicates.
As this is the "Company Folder", you should rename it accordingly. In my case, I just used my name. Right click the "Company Folder" and add another folder, which is the program folder, and rename it "Custom Cursor". The file system should now look like Figure 07.
Right click the "Custom Cursor" folder, point to "Add" and then click "Project Output" in the fly-out menu. The next window will look like Figure 08.
Just to check that everything is going to be fine, you should see "Custom Cursor" as the project, the primary output should be selected, and the configuration should be set to "(Active)". When this is so, click "OK".
Right click the application folder again and choose to add a file. Browse to the bin folder and double click the cursor file. Repeat this step to add the program icon.
Your file system should now look like Figure 09
Right click the "primary output" and choose "Create shortcut …". Rename the shortcut to "Custom Cursor" and click somewhere to confirm the change. Click the shortcut once and browse for your program icon in the application folder from the Properties window as Figure 10 shows. The icon is not visible in the system files, but it will be in the program.
If you want to create a shortcut on the desktop, move the shortcut you just created to the "User's Desktop" folder by dragging it there. Create a second shortcut and drag it to the "User's Programs Menu" folder. Just don't forget the icon.
Click the application folder once and go to the Properties window. Change the default location from [ProgramFilesFolder][Manufacturer]\[ProductName] to the following:[ProgramFilesFolder][George Poth]\[Custom Cursor]. Of course, the name must be the name you used when you renamed the "Company Folder", and the program folder must be the same name you used when you renamed the program folder.
Click the "Installer Sample" in the Solution Explorer. There are some changes you should make in the Properties window according to the following table:
|Property:||Changes to be made:|
|AddRemoveProgramsIcon||Browse for the program icon in the application folder.|
|Description||Write a short description if you want.|
|Manufacturer||Your website, pay attention to the required format: (http://www.myweb.com) or your e-mail (mailto:firstname.lastname@example.org)|
|Subject||Additional information about the application.|
|SupportPhone||Your support phone number.|
|SupportURL||A website with support/help.|
From the build menu, choose "Build Installer Sample". When you're through, choose "Install" from the project menu. When the installation is complete, you will see the program in the menu (Figure 11) and on your desktop (Figure 12).
Open the Control Panel and go to Add/Remove Programs. You will see the program installed as Figure 13 shows.
Click the Installer Sample and open the information about support. You will see Figure 14. You could click the link to send an e - mail or to go to the author's web, depending on what changes you made in the Properties window.
In the IDE, change the solution configurations from Debug to Release, as Figure 15 shows.
From the Build menu, click Build Installer Sample as Figure 16 indicates.
When you're through with that, have a look at the output window as shown in Figure 17. Among other things, you will find this line: "WARNING: This setup does not contain the .NET Framework which must be installed on the target machine by running dotnetfx.exe before this setup will install. You can find dotnetfx.exe on the Visual Studio .NET 'Windows Components Update' media. Dotnetfx.exe can be redistributed with your setup." That means that you must install the same version of the .NET Framework on a user's computer with which you have compiled your application before you can install your program. You could distribute it with your CD; or at least give the user the link to download it. However, if you tell your user to download the framework, make sure he/she knows which version to download. The Microsoft Visual Basic .NET Edition 2002 needs version 1.0, and the Edition 2003 needs version 1.1. If the same version of the framework is already installed on the user's computer, the .NET Framework Setup will tell them so. Both .NET Framework versions can be installed on the same machine.
Now that you have the installer, open the Visual Studio Projects folder. If you have installed Microsoft Visual Basic .NET in the default location, then the folder should be here: C:\Documents and Settings\UserName\My Documents\Visual Studio Projects (This path might be different on other operating systems than XP).
Open the Installer Sample folder, and inside this folder, the Release folder. You will see the items as in Figure 18. The selected item in Figure 18 is your installer. On other operating systems than XP, you might have to look for the file extension (Installer Sample.msi). This is the file you need to copy to a media so as to install it on another computer.
Double-click the installer and you will see the Welcome Screen as in Figure 19.
Click "Next" to go to the next window in which you can arrange the installation as Figure 20 shows.
Click next to see the window in which you have to confirm the installation as you can see in Figure 21.
Click next to install as shown in Figure 22.
When the setup is complete you will see Figure 23.
Click "Close" to exit. The program is now installed. To uninstall or repair the program, you can use the Add/Remove Programs window in the Control Panel, or you could repeat the installation process.
At this place, I'd like to thank Ged Mead (XTab). Not only for of his invaluable help on this article, but also for his important help and his patience throughout the past seven months during which we have been in touch.
Related devCity.NET articles: