Issue dated - 9th February 2004

-


Previous Issues

CURRENT ISSUE
INDIA NEWS
NEWS ANALYSIS
COLUMNS
TECH FORUM

THE C# COLUMN

BETWEEN THE BYTES
TECHNOLOGY
SPECIALS <NEW>
Symantec Report
Security Headquarters
JobsDB
MINDPRINTS
HMA BANKBIZ
EC SERVICES
ARCHIVES/SEARCH
IT APPOINTMENTS
Openings At Jobstreet.com
WRITE TO US
SUBSCRIBE/RENEW
CUSTOMER SERVICE
ADVERTISE
ABOUT US

 Network Sites
  IT People
  Network Magazine
  Business Traveller
  Exp. Hotelier & Caterer
  Exp. Travel & Tourism
  Exp. Pharma Pulse
  Exp. Healthcare Mgmt.
  Express Textile
 Group Sites
  ExpressIndia
  Indian Express
  Financial Express

 
Front Page > TechSpace > Story Print this Page|  Email this page

The C# column

Deploying .NET applications - I

Though distributing libraries in the form of DLLs was a major step forward, it suffered from the now infamous DLL hell. COM could avoid this but it had no versioning mechanism. Moreover, a COM component had footprints at so many places that if one of them got modified/corrupted, the application used to break down. .NET has come up with more sophisticated approaches for deployment and versioning.

Deployment issues

Deployment is a process by which you distribute a finished application or component to be installed on other computers. In Visual Studio .NET, deployment is based on Microsoft Windows Installer technology. Microsoft Windows Installer is a service shipped with Windows ME, Windows 2000, and Windows XP. It is used for installation and configuration of applications to be installed.

Every .NET application is deployed in the form of one or more assemblies. Assemblies may be deployed as regular standalone files (DLL or EXE files), or they may be deployed using CAB, MSI, or MSM files. The simplest way of deploying a private assembly is to use an XCOPY, i.e. copying the assembly in the desired folder. On the other hand we can deploy shared assemblies by installing them in the Global Assembly Cache of the target machine by using the Gacutil.exe.

To help programmers develop setup and deployment solutions, Visual Studio .NET provides several templates and wizards. We can create a setup or deployment project by selecting ‘Setup and Deployment Projects’ in the ‘New Project’ dialog box shown in the following figure.

Let us first discuss the types of projects shown in the dialog box and see the usage of each. Later we have illustrated how to deploy different types of applications using these projects.

* Setup Project

A setup project builds a Windows Installer file or an MSI file with the .msi extension. This file is used to install the specified files and resources on the target machine automatically. The .msi file contains the application, any dependent files, information about the application such as registry entries, and instructions for installation. When the .msi file is distributed and run on another computer, you can be assured that everything necessary for installation is included; if for any reason the installation fails (for example, the target computer does not have the required operating system version), the installation will be rolled back and the computer returned to its pre-installation state.

* CAB Project

A CAB project creates a cabinet file with the .cab extension. It is much like a Zip file, compressing a number of specified files into an easy to use and easy to deploy package. The resulting cabinet (.cab) file can then be deployed or downloaded. The files present in the .cab file can be extracted by double-clicking the .cab file.

* Merge Module Project

A Merge Module project produces a merge module file having a .msm extension. A Merge Module is a single package that contains all files, resources, registry entries, and setup logic necessary to install a component.

Merge Modules are used to install components that are shared by multiple applications. The basic distinction between a Merge Module (.msm) and a Windows Installer (.msi) is based on the user using these components. Whatever we wish to deploy directly to the end-user of the application (executable files, documents, HTML pages) should be packaged in a Windows Installer, whereas, whatever we wish to deploy to the developer (DLLs, controls, resources) should be packaged in a Merge Module. The developer can then repack it in a Windows Installer for distribution to the end-user. It is possible to put multiple components into a single Merge Module but it’s best to create a Merge Module for each component in order to handle versioning problems. Once you have distributed a Merge Module it should never be modified; instead you should create a new Merge Module for each successive version of your component.

* Web Setup Project

Web Setup Project helps us to deploy Web-based applications. In addition to this, any Windows application or its installer can be deployed to a Web server so that users can later download and run them from a website. In order to deploy Web-based applications we will have to build a Web Setup Project, copy it to the Web server and run the installer to install it on the server.

* Setup Wizard

The Setup Wizard is used to help us start creating any of the above-discussed projects in a fast and simple manner. We just have to follow some simple steps the wizard leads us through and the wizard does the initial job for us. Next we may extend the project further as per our requirements. Now let us understand the projects discussed above in detail.

Setup Projects

We know that a Setup Project creates a .msi file, which actually installs the application on the target computer. To demonstrate this we plan to deploy a simple Windows application using the Setup Project. Here we have assumed that the Windows application stands created and the .EXE named windowsapp1.exe is ready. To deploy this Windows application we need to select ‘New | Project’ and select ‘Setup and Deployment project’ from the available options. Next we must select ‘Setup Project’ as the project template and specify the name (say winsetup) and the location of the setup project and click OK. Then we are taken to the File System Editor. The File System Editor is shown in the following figure.

The File System Editor has three folders—the Application Folder, the User’s Desktop folder and the User’s Programs Menu folder. These folders actually represent the folders on the target machine. For example, whatever you put in User’s Desktop will be deployed on the desktop of the target machine. From the three folders in the file system editor, files from Application Folder would be deployed in the Program Files folder; typically it is ‘C:\Program Files\Company Name\Application Name’ of the target machine. User’s Desktop folder contains files and folders that would appear on the desktop of the target machine on a per-user basis. Typically the path is ‘C:\Documents and Settings \username\Desktop’. User’s Programs Menu folder contains user’s program groups that would usually get deployed in ‘C:\Documents and Settings \username\Start Menu\Programs’.

Now we need to add the Windows application EXE file into this project. For this we must right-click on the Application Folder. A menu opens up. We must select Add | File and on doing so an ‘Add Files’ dialog pops up. Now we need to browse for ‘windowsapp1.exe’ file so that it gets added to the Application Folder. We can add the EXE to User’s Desktop and User’s Programs Menu as well but while doing so we must keep in mind that these two folders are on per-user basis. This means that only the user who installs the application would be able to access the file on his desktop and not the other users.

This completes the basic steps needed to build an installer. We can now build this project and an installer called ‘winsetup.msi’ gets created in the debug folder. Now all we need to do is to distribute this installer, and on running the installer on the target machine the application would get installed there.

On running the installer we get a series of screens depicting different stages of installation. Note that if our application needs more files than just the ‘windowsapp1.exe’ then we can copy them to any of the above-mentioned folders.

There is much more to a Setup Project than what we discussed above. We saw the simplest form and there are several more features that we need to explore. All the deployment capabilities discussed below are not mandatory and we can customise our installation process according to the needs of our application.

* Adding Shortcuts

We can add shortcuts to our application in any of the 3 folders. For this we need to right-click on the application file (‘windowsapp1.exe’) that we added to the project and select ‘Create shortcut to windowsapp1.exe’. On doing so a shortcut for our application would get created. Now we must drag this shortcut in the User’s Desktop Folder. If we wish to add a shortcut in User’s Programs Menu also, we need to create another shortcut in the same manner discussed above and drag it in the folder. On building and installing the application, the shortcuts get added in the specified folders of the target machine.

* Adding Registry Entries

We can make a provision that some registry entries would be added for a particular application during installation of the application. We can then access these entries later through our application’s code at run-time. To add the registry entries we must right-click on winsetup in the Solution Explorer and select View | Registry. On doing so we will be presented with the Registry Editor shown in the following figure.

To be continued…

Yashavant Kanetkar, one of the first Express Computer columnists, is an established software expert, speaker and author with several best-sellers to his credit, including titles like “Let Us C” and the “Fundas” series. Contact him at kanetkar@dcubesoft.com
<Back to top>


© Copyright 2003: Indian Express Group (Mumbai, India). All rights reserved throughout the world. This entire site is compiled in
Mumbai by The Business Publications Division of the Indian Express Group of Newspapers.
Please contact our Webmaster for any queries on this site.