Monday, August 25, 2008

Deploying .NET Applications - III

Merge Modules are a feature of Windows Installer that provides a standard method for delivering components, ensuring that the correct version of a component is installed. Merge Modules is something that we would give to a developer and not the end user. For example, if we want to distribute our DLL to another developer, we’ll create a Merge Module for it and distribute our DLL in a Merge Module. While deploying a finished product the developer will include this Merge Module in his MSI project and give it to the end user. Merge Modules are used to install components that are shared by multiple applications.

Now let us proceed with creation of a Merge Module. Here we have assumed that a Class Library stands created and the .DLL named ‘mylib.dll’ is ready. To create a merge module we need to select Merge Module from the project templates available and name it, say mergesetup. On doing so we are taken to the File System Editor. The File System Editor is shown in the following figure.

The File System Editor has two folders—Common Files Folder and Module Retargetable Folder falling under ‘File System on Target machine’. Files present in a Merge Module are generally sharable files hence Common Files Folder is a good option to deploy the files. Whichever file we copy in this folder gets deployed to the Common Files folder of the target machine. Here too we have an option of adding special folders to the File System Editor by right clicking on the left pane and selecting the desired folder. Files deployed in these folders would get deployed to corresponding folders on the target machine.

The other folder, i.e. the Module Retargetable Folder, offers a lot of flexibility in deciding where files should be installed. Let us see how. Now suppose the author of the merge module is not sure where the developer wants the file to get deployed on the end user’s machine. In such a case the author of the Merge Module must copy this undecided file into the Module Retargetable Folder and set a default location for this file using the Properties window. This gives the developer a chance to change or retarget the location of the file later while deploying the whole application to the end user. Let us see how it is done.

For this we need to copy ‘mylib.dll’ in the Module Retargetable Folder and set the DefaultLocation property of the Module Retargetable Folder to [GAC]. Next we must build the Merge Module. On doing so a ‘mergesetup.msm’ file would get created in the debug folder. We can now give this ‘.msm’ file to the developer.

Now assume that the developer creates a Setup project called ‘msimerge.msi’. To add the Merge Module to the project he needs to right click on the project name in the Solution Explorer and select Add | Merge Module. He can then browse for ‘mergesetup.msm’ and add it to his project. Now to retarget the file all he needs to do is open the Properties window of the ‘mergesetup.msm’ and set the Module Retargetable Folder property to any desired location. For example, if he wants the file to get installed in Common Files Folder and not GAC as specified by the author of the Merge Module then he might change the property. The Module Retargetable Folder property falls under the MergeModuleProperties in the Properties window.

Now whenever the end user installs the ‘msimerge.msi’, ‘mylib.dll’ gets installed in the Common Files Folder. Note that the developer can (and surely will) add his own application and associated files in ‘msimerge.msi’ along with ‘mergesetup.msm’ for deployment.

CAB Projects

Unlike the other deployment project types, there are no editors provided for working with CAB projects. Files and project outputs can be added to a CAB project through Solution Explorer, and properties can be set in the Properties window or in the Project Property pages.

For .NET deployment, a CAB file can contain only one assembly, and the CAB file must be assigned the same name as the contained assembly, but with the ‘.cab’ extension. For example, if we create a cabinet file for ‘mylib.dll’, we need to name the cabinet file as ‘’. Creating a cab file is very simple. Let us see how to create it.

To create a Cabinet or CAB project we select the Cabinet Project template from the New Project dialog and name it, say mylib. To add files to this project, we need to right click on the project name and select Add | Files. This would add the specified files in the project and on building the project the ‘’ file would get created which can be deployed to target machines. Double clicking on the cab file extracts the files compressed in it.

Deploying Windows Applications On Web

We have discussed two cases here. First we have explained the method by which a Windows application (.exe) can be executed directly on the web and second by which an installer (.msi) of the Windows Application can be downloaded from the web. For both the scenarios we have assumed that ‘windowsapp1.exe’ stands created. And for both we first need to create a Web Setup project.

To create a Web Setup project we selected the Web Setup Project from the project templates and named it websetup. On doing so, the File System Editor of websetup would get opened. Now we need to add ‘windowsapp1.exe’ to the Web Application Folder as shown in the following figure.

Next we need to change two of the properties of the Web Application Folder. First we have to set the AllowDirectoryBrowsing property to True. This property determines whether users can see a hypertext listing of files and subdirectories in a virtual directory. If it is set to True, users can browse for it. Next we have to set the VirtualDirectory property to myweb. Now we need to build websetup and copy the ‘websetup.msi’ file to the web server. On double clicking the MSI file the project would get installed. To test the project we need to start Internet Explorer and type the ‘http:\\computername\myweb’ URL. You will see the name of the ‘windowsapp1.exe’ file in the browser window. On clicking filename the EXE would get executed. For the second scenario we need to follow the same steps as given above, but instead of copying the EXE to the Web Application Folder, we need to copy an MSI (winsetup.msi) project, which includes the EXE to the folder. Then on deploying and installing ‘websetup.msi’ we would get the window displaying the name of the ‘websetup.msi’ file. On clicking it we would be presented with a dialog box that gives us options to install or download the MSI. On installing or downloading the MSI we would be able to execute the Windows application.

Setup Wizard

As told to you earlier the Setup Wizard helps us to start the deployment projects. The wizard guides us through the steps of creating setup program that contains all information required for installation. The steps in the Setup Wizard are self-explanatory. As soon as we select Setup Wizard, give the project a name (say wizsetup) and press OK, we are presented with a Welcome dialog.

On clicking ‘Next’ we are presented with the Step 2 window of the wizard. It asks us type of project we intend to make. Suppose we select the first option and click ‘Next’, we get the third dialog box. Here the Wizard asks us to add the files we wish to deploy. We can add the files by clicking on the ‘Add’ button and browsing for the desired files. On clicking the ‘Next’ button the Wizard presents us with the summary of the project. We had selected the first option and hence on clicking the ‘Finish’ button the Wizard takes us to the File System Editor of the project. We can now build the project as we would build any deployment project.

Your Title