Sometimes our application may require        some pre-requisites before installation. For example, our application may        demand that Internet Explorer 5.0 or higher must be installed on the        target machine. This calls for a check that must be satisfied for        successful installation of the application. We can apply Launch Conditions        in such cases. If the condition specified during this step (here, Internet        Explorer installed) is not fulfilled then the installation halts. Note        that here this step is intended to demonstrate the concept of launch        conditions and ‘windowsapp1.exe’ has no actual dependency on Internet        Explorer.
     
      To add launch conditions we need to right click on the project in the        solution explorer and select View | Launch Conditions. On doing so a        Launch Condition Editor will get opened. Next we need to right click on        the Requirements on Target Machine node and we would be presented        with 5 options to choose from—Add File Launch Condition, Add Registry        Launch Condition, Add Windows Installer Launch Condition, Add .NET        Framework Launch Condition, and Add Internet Information Services Launch        Condition. As the names suggest we can check for the specified entities on        the target machine and if these entities are present on the target        machine, the installation proceeds otherwise it halts.
     
      Here we have added the Add File Launch Condition. On doing so two nodes        called Search For File1 and Condition1 would get added in        the Search Target Machine and Launch Conditions nodes        respectively falling under the Requirements on Target Machine node.        We changed the properties shown in the following table for the Search        For File1 entity.
     
 
| Property | Changed to... | Used | 
| Name | Search For Internet Explorer | Specifies the name used in Launch Condition Editor. | 
| FileName | Iexplore.exe | Specifies the name of a file to search for. | 
| Folder | [ProgramFilesFolder] | Specifies the folder where a file search will start. | 
| Depth | 3 | Specifies the number of levels of subfolders to search for a file. | 
| MinVersion | 5.00 | Specifies the minimum version number for a file in the file search. | 
Now we need to specify the launch        condition. To do so we must set the Condition property of the        Condition1 entity to FILEEXISTS1. Note that in the Properties        window of Search For File1 the Property property is set to       FILEEXISTS1. We can also specify a message through the Properties        window that would be displayed if the condition evaluates to false (i.e.        if file is not found) at installation time.
     
      Changing Icons
     
      We can change icons for our application using the Properties window. To        change the icon for the shortcuts we must select the shortcut file and set        the Icon property of the file to any .ico file. Note that we        need to first copy this file to the Application Folder to make it        available.
     
      On the same lines we can change the icon of the setup file that would be        displayed in the Add/Remove Programs Window. To do so, we must right click        on winsetup in Solution Explorer and select Properties. This would        display the Properties window of the whole solution. Here we need to set        the AddRemoveProgramsIcon to any desired file.
     
      Adding File Associations
     
      Suppose our application creates files having the user–defined extension        (for example, we can serialize data in a file having the .mine        extension) and now we wish that on double clicking such a file it should        automatically get opened in our application. To achieve this we must use        file associations. File Associations allows the developer to associate        user-defined file types with his or her application. Assume that we need        to deploy a file called myfile.mine with our application. To deploy        it along with the application we first need to copy it in the Applications        Folder. After installation whenever the user double clicks on this file it        should get opened with windowsapp1.exe. Note that here too we have        made an assumption for demonstration purpose that our application is        creating files having .mine extension. Actually windowsapp1.exe       is too simple and does not do any serialization or file I/O.
     
      Now to associate this file with our application we must right click on the        project name in the Solution Explorer and select View | File Types. On        doing so we are presented with the File Types Editor. Next we need to        right click on the node and select Add File type. Now we need to give any        file name (here we have used file1) along with the extension (.mine)        in the Properties window. This ensures that any file with the .mine        extension would get opened with our application. Note that we need not        specify the dot ( . ) while mentioning the extension. After this we have        to set the Command property of the file to windowsapp1.exe.        The File Types Editor along with the Properties window is shown in the        following figure.
     
      Now on re-building the project and running the installer, myfile.mine       would get deployed along with the application. And moreover whenever        the user double clicks on this file it gets opened with our application.
     
      Adding Custom Actions
     
      Custom actions allow us to run code at the end of an installation to        perform actions that cannot be handled during installation. For example,        if we wish to create a database after installation and before running the        deployed application, we need to add the DLL or EXE, which would create a        database, as a custom action. We can add custom actions through the Custom        Actions Editor. The Custom Actions Editor can be opened by right clicking        on the project name and selecting View | Custom Actions. The Custom        Actions Editor is shown in the following figure. 
This editor contains four folders,            each corresponding with a phase of installation—Install, Commit,            Rollback, and Uninstall. Custom actions are run in the same order that            they are displayed in the editor. They can be reordered by dragging            with the mouse or through the Cut and Paste commands on the Edit menu.            All the Custom Actions run at the end of installation. In addition to            the custom actions we add, there are 5 pre-defined custom actions            included in Visual Studio .NET—Event Log, Message Queue, Performance            Counter, Service, and Service Process components. We can also add            these pre–defined Custom Actions in our project.
         
          Deploying to Special Folders
         
          In addition to the folders mentioned in the previous            section—Application Folder, User’s Desktop, and User’s Programs            Menu—we can add more folders to the File System Editor through the            ‘Add Special Folders’ menu. If we right click on the left pane of the            File System Editor we get a popup menu offering fourteen folders from            which we can select the ones that we can add.
          On selecting a folder from this menu it gets added to the ‘File System            on Target Machine’ tree. This provision is made so that we can deploy            our files to these specific folders on the target machine. For            example, if we have a signed assembly and we wish to deploy it in the            Global Assembly Cache of the target machine, all we need to do is add            the Global Assembly Cache folder in the File System Editor and copy            our signed assembly to it. On installing the application on the target            machine one can find the assembly installed in the Global Assembly            Cache.
         
          That brings us to the end of discussion on how we can customize our            MSI project according to the requirement of the application we want to            deploy. If we wish to deploy the application on the development            computer while building it, we have to right click on the project name            in the Solution Explorer and select Install. And if we wish to deploy            it on another computer then, as it might be very obvious to you by            now, we need to distribute the winsetup.msi file.  
 
No comments:
Post a Comment