Creating Installation Components

Creating Installation Components

The .NET Framework provides the Installer class, which is defined in the System.Configuration.Install namespace. This class is specifically designed to help you perform customized installation actions.

Understanding the Installer Class

The System.Configuration.Install.Installer class works as a base class for all the custom installers in the .NET Framework. Some of the important members of the Installer class are listed in Table 14.2.

Table 14.2. Important Members of the Installer Class

Member Name

Type

Description

Commit()

Method

Executes if the Install() method executes successfully

Install()

Method

Performs the specified actions during an application's installation

Installers

Property

Specifies a collection of Installer objects that are needed for this Installer instance to successfully install a component

Rollback()

Method

Is called if the Install() method fails for some reason to undo any custom actions performed during the Install() method

Uninstall()

Method

Performs the specified actions when a previously installed application is uninstalled

You can derive a class from the Installer class and override the methods listed in Table 14.2 to perform any custom actions.

If you want the derived Installer class to execute when an assembly is installed by using a Web setup project or the Installer tool ( installutil.exe ), you need to apply the RunInstaller attribute on the class and set its value to true , like so:

 [RunInstaller(true)] 

The Installer classes provide the infrastructure for making installation a transactional process. If an error is encountered during the Install() method, the Rollback() method tracks back all the changes and undoes them, leaving the machine in the clean state it was in before the installation process started.

Working with Predefined Installation Components

Most of the components available through Server Explorer have predefined installation components associated with them. For example, when you click the Add Installer link for an EventLog component, a ProjectInstaller class is created in the project and the installation component for the EventLog component is added to this class (see Figure 14.3). If you add more installation components (for example, a PerformanceCounter installation component) to this project, they are all added to this ProjectInstaller class. These installation components are actually added to the Installers collection of the ProjectInstaller class.

Figure 14.3. The Add Installer Link adds a predefined installation component to your project.

graphics/14fig03.jpg

When you compile the project to build an EXE or a DLL file, the ProjectInstaller class is part of the output assembly.

Deploying an Assembly That Contains the Installation Components

You can deploy an assembly that contains installation components in two ways. These techniques are covered in the following sections.

Deploying an Installation Component Using the Web Setup Project

To deploy an application that consists of installation components, you need to create a Web setup project as you normally would. However, this time, you use the Custom Actions Editor to deploy the necessary additional resources. At the time of deployment, the deployment project executes the ProjectInstaller class as a part of its custom installation action to create component resources.

Deploying an Installation Component Using the Installer Tool

You can also use the command-line Installer tool ( installutil.exe ) to install the assemblies that contain additional component resources.

To install the resources contained in an assembly named Assembly1.dll , you could use the following form of the installutil.exe command:

 installutil.exe Assembly1.dll 

You can also install resources contained in multiple assemblies, as follows :

 installutil.exe Assembly1.dll Assembly2.dll Assembly3.dll 

If you instead wanted to launch the uninstaller for installation classes stored in an assembly, you would use the /u or /uninstall option with the command, as follows:

 installutil.exe /u Assembly1.dll 
graphics/alert_icon.gif

If you are installing components from multiple assemblies using the installutil.exe command, and if any assembly fails to install, installutil.exe rolls back the installations of all the other assemblies. However, the process of uninstallation is not transactional.


Working with Installer Classes

You can add your own Installer classes to a project to perform custom actions, such as creating a database on a target computer, during installation. These compiled installer classes from the project are then added to the deployment project as custom actions that are run at the end of the installation. The following are typical actions you would perform while creating a custom installer class:

  1. Inherit a class from the Installer class.

  2. Make sure the RunInstaller attribute is set to true in the derived class.

  3. Override the Install() , Commit() , Rollback() , and Uninstall() methods to perform any custom actions.

  4. In a setup project, use the Custom Actions Editor to invoke this derived class to perform the required processing.

  5. If necessary, pass arguments from the Custom Actions Editor to the custom Installer class using the CustomActionData property.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net