Oct 20, 2011

VS.NET Setup Projects

Section II: VS.NET Setup Projects
II-1: Project Types
There are five types of setup and deployment projects in VS.NET, but three are of significant importance that are "SetUp Project", "Web Setup Project" and "Merge Module Project".

Display 1: Project Type dialog.
  • Setup Project

    Generic type of project that could be used for all type of applications including web based application.
  • Web SetUp Project

    Name suggests the type; this project type helps in creating virtual directories for web based applications during installation.
  • Merge Module Project

    When you want to install some additional third party software like MSDE along with your application then you can use this type of project. Use a *.msm extension based merge module installation of MSDE along with your own and create a setup. 
II-2 Get Started
1) Select a SetUp Project type as shown in Display 1.

2) The default File System editor will appear in the window as shown in Display 2.

Display 2: Default File System Editor
3) One can add special folders here into which they intend to add files. Just right click on the editor to view the special folder types available. These are the folders into which you can drag and drop an entire folder structure with files.
4) Click on Registry editor and navigate to that editor (Display 3). One can configure registry settings here like "Manufacturer's name", "Version No", etc.

Display 3: Using registry editor
5) There is also Launch Conditions editor available. This is of greatest use since one can pre-validate for certain rules even before installation.
Validations can include file search, registry search, Component search or a particular deployment condition like as we mentioned earlier in section 1-2-b). Consider Display 4 where I added a Launch Condition and set the property condition as "PhysicalMemory>10000" i.e. 10GB and gave a custom error message "Physical Memory is less than 10GB." After the build when I tried to install it gave me error message as shown in Display 5 and cancelled the installation process, obviously my system had less than 5GB HD space and condition evaluated to false.
Note: For List of properties available go to MSDN help and search on Property Reference. There is a launch condition "MsiNetAssemblySupport" by default. This can be removed if computer on which your application is being installed does not support CLR.

Display 4: How to add condition to Launch condition.

Display 5: Launch validation!
6) File types editor is used to associate a default command action, File description , icon and extension for your custom files. There are many occasions we create new file-types with extensions like ".rmt" or ".cpg" etc. With the arrival of Win2k3 the rules specify that all files should have a default open command and an icon association. Please refer to display 7 and 8.
Note: Command association for the file is a must, hence need to associate an exe file.

Display 7: Configure default icon and extension for the file type.

Display 8 : Open command associated with the Notepad exe.
7) User Interface editor is provided in VS.Net by default with certain additional dialogs as per the requirements (refer display 9). Add for e.g. Textboxes (A) option that provides you with 4 textbox with edit value, label and property (Display 10). This is the most important editor since this is the UI that interfaces between the user and your MSI setup. The values captured from here are used throughout the installer like in Custom actions.

Display 9: Default view of User interface editor.

Display 10: See the EditLabel, EditProperty and Editvalue attributes.
Here if we pass the Editvalue as "Orbit-e", change EditLabel as Companyname and EditProperty as "COMPANYNAME"; in my custom actions section when I read the property "COMPANYNAME" it gives me "Orbit-e". This is the editor where in one can ask user to enter Company details, some configuration information like connectionstring for database etc.
8) Custom actions editor is where one adds some custom built *.exe, *.bat, *.wsh and other script files. As an example I have added a new C# windows application project as in Display 11. The following code in display that has a "Messagebox.Show" for a command line argument received. This could very well be any other functionality instead of Messsagebox.Show.

Display 11: Entry point has arguments to receive.
Once this is done, click Custom actions editor->Install->Add Custom action. This gives a dialog as shown below in display 12. Select Application folder->Add Output->Primary Output->Ok->Ok.

Display 12:Select application folder.
Now we are ready to pass the arguments for this primary output file as shown in Display 13. Pass the string [COMPANYNAME] in the "Arguments" (Pass multiple argument with some delimiter that is not a keyed character in same manner). Check "InstallerClass" property to False. This should be true only if this is a .Net installer class that can be used to programmatically access the MSI setup instances and databases. We will not discuss this since this is out of scope from this context.

Display 13: Configure the Custom action properties
NOTE: Refer to MSDN on types of custom actions and when are they fired, since this is crucial for your cleanup process in your un/installation.
9) Installer setup is now complete. Build the project and try to install. At one point in the installation process the setup throws up a Messagebox (Display 14) with the Winform and will continue only after this form is closed, since all these form part of a single installer session. This value was the same that was entered in the User Interface editor.

Display 14: Messagebox display from the Custom exe.
Note: There is one property that helps a lot that is [TARGETDIR] that gives the path where the user selected your application to install.
Though I have not been able to discuss complete technical features of VS.NET to create MSI, the features discussed in this article with some individual reading are very much sufficient to create a professional MSI installer. Installers are helpful for your deployment process but are not the only thing that affects this process; proper versioning of your assembly/dll's is also of primary importance. Happy Programming!


Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib