Compartir a través de


How to: Override Default Methods on Installation Components 

By default, every installation component has the following methods:

  • Install — All of the installation functions the installer must perform are carried out within this method. The Installer1class (or any class with the RunInstallerAttribute value set to true) calls Install on each of the installation components it contains, and then calls either Commit (if the installations were all successful) or Rollback (if any errors occurred).

  • CommitCommit is called after the Install method has been successfully run on all of the installation components the installer class contains. At this point, all of the installations are committed. Usually, to avoid raising exceptions, no processing is done in the Commit method.

  • Rollback — The Rollback method is used to undo all previous installation work if an error occurs anywhere within the installation process. If any of the installation components contained by the installer class raises an error, all of the installations carried out so far are undone.

  • UninstallUninstall is used to remove installation component resources from the system. Unlike installation, uninstall is not transactional. If one uninstall process fails, the system still attempts to uninstall all of the other resources.

Each of these methods contains default processing that will carry out the required work without modification. If desired, however, you can override and modify the processing in each step. For example, for a ServiceBase installation component, you might want to modify the default processing that occurs in the Commit procedure so that the installation process starts the service after it is successfully installed. You might also modify the Uninstall procedure so that each service is stopped before it is uninstalled.

To override default methods for an installation component

  1. After adding an installation component to your solution, open the installer class.

  2. Locate the installation component you want to modify, and access it in the Code Editor.

  3. Override the appropriate method and add the functionality you want. For more information, see Overriding Properties and Methods.

    NoteTip

    Make sure to retain the original processing necessary to install, commit, rollback, or uninstall your resources when you override methods in the Installer1 class. In general, you should add code to the existing functions rather than removing existing functionality.

See Also

Tasks

How to: Add Installation Components to Your Projects
How to: Configure Installation Components
Walkthrough: Installing an Event Log Component

Concepts

Overriding Properties and Methods