Saturday 2 June 2012

Creating a Set Up Project


If you have ever wanted to build your own Windows Installer and you have access to Visual Studio .NET it is much easier than you may think and of course it is much less expensive than many other third party installer applications. While third party installer applications may provide a greater variety of options, I have found the the Setup and Deployment Projects within Visual Studio .NET work perfectly fine in many cases. This article will walk through the step by step process of building a Setup Project.
There are five different templates that are available when you select the project type 'Setup and Deployment Projects'.

Figure 1: Add New Project Dialog
  1. Setup Project: Creates a Windows Installer project to which files can be added. This project type is the most generic of the five.
  2. Web Setup Project: Creates a Windows Installer web project to which files can be added.
  3. Merge Module Project: Creates a Windows Installer Merge Module project to which files can be added. This project type is most commonly used for using third party products.
  4. Setup Wizard: Creates a Windows Installer project with the aid of a wizard.
  5. Cab Project: Creates a Cab project to which files can be added.
For the purpose of this article, I will be using the template Setup Project. Provide a name for the project as well choose the location where this project will be established. (See Figure 1) Once you have done this click 'OK' and you should now see a screen comparable to the following.

Figure 2: Default File System View
Now that you have an empty Setup Project established let us now discuss the available editors.
Setup Project Editors And The Functionality They Provide

[ download code ]
The next item we will discuss are the various editors that are available.
  1. File System Editor (displayed in Figure #2)
  2. Registry Editor
  3. File Types Editor
  4. User Interface Editor
  5. Custom Actions Editor
  6. Launch Conditions Editor
There are several ways you can access these editors. Here I will illustrate two of these methods.

Figure 3: Access the various editors
As you can see in the above figure I have indicated two ways to access these editors. In example number one a single click on the setup project you have created with Solution Explorer provides a menu of the various editors. Whereas in example number two if you right click on the setup project and then click ?View? you are then provided access to the various editors. Basically it is simply a matter of choice as to which method you desire.
File System Editor
The File System (Figure 4) provides you the essential tools to work with the application folder, user's desktop, and the user's programs menu.

Figure 4: File System Properties
The first thing we want to do here is to include the relevant files and folders we wish to install on the user's machine. This is accomplished by right clicking the Application Folder and selecting 'Add'. In this case I will choose 'Folder' and give this newly established folder the name of 622. Now to add files to this folder, right click the folder 622 and choose 'Add'. Merely add one or more of the files that is vital for your application. Now that you have you files and folders in place you could take additional steps such as manipulating the user's desktop with items such as a shortcut, as well you can add a program group to the user's program group. The following screenshot is an example of something similar you may see.

Figure 4.1: File System Properties
If you have a requirement to modify the user's registry then the Registry Editor is a straight forward tool that provides this capability.


Figure 5: Registry Editor
Next is the File Types Editor. If you need to establish file associations on the user's computer with your application then this editor will achieve the desired task.

Figure 6: File Types Editor
The next item you find of immense importance is the User Interface Editor. Inside of this editor you may eliminate or include dialogs that are needed for this install project. The following screenshot is the default User Interface that is created when I initially created this setup project (See Figure 1). The only variation is that I have added a Customer Information dialog.

Figure 7: User Interface Editor
To include the Customer Information dialog that I spoke of follow the following steps.
  1. Under Install right click on the 'Start' node
  2. Choose 'Add Dialog'


Figure 7.1: User Interface Editor
  1. Select the Customer Information Dialog and click 'OK'
As you can see there are is an ample variety of dialogs you can choose from. Take the time to look over each one and understand the use behind them.

Figure 8: Custom Actions Editor
The Custom Actions Editor allows you to specify additional actions to be performed on the target computer at the end of an installation. For the purpose of this article, I am not going into details relating to custom actions rather to learn more on this subject read up on Custom Actions Management in Deployment.

Figure 9: Launch Conditions Editor
In the above example, I have added a condition to verify that the user's computer has at least 128MB of RAM. If the user's computer does not meet this stipulation then the application installer will graciously inform the user of this stipulation and exit the install process. As you have probably already concluded this feature can be significant in many aspects, for example; free space on the hard drive and the amount on installed memory just to name a couple. There is nothing more embarrassing from a developer's point of view to have your application fail at the install process. If you take time and think of this, would you be impressed with an application you are looking forward to using only to have the install process fail?
Now we will take a moment to look at the Physical Memory launch condition that I have created. To add new conditions do the following.
  1. Right click Launch Conditions and choose 'Add'
  2. Provide a name for this condition such as I have in this example
  3. Right click the 'PhysicalMemory' condition and choose 'Properties'
In this case the condition I have established is that the physical memory must be greater than 128 MB. Be sure to look at the Windows Installer Property Reference regarding the various properties that are available when working within the Launch Conditions Editor.
The Setup Project All Comes Together

[ download code ]
As I have indicated it is fairly simple and straight forward to create a Setup and Deployment Project. I have covered adding a new project, the six types of editors available and examples of how to best utilize these editors. While I have not covered the all the complete features of the Windows Installer I should have provided enough to peak your curiosity. While some may state that the Windows Installer may not be sufficient, I must disagree. As with anything else the choice of the installer is based upon requirements. Take the time to create your own Windows Installer yourself and see what you opinion is. Here is a screenshot of this Windows Installer that we have just discussed.


No comments:

Post a Comment