|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Add Installers to Your Service Application
Visual Studio ships installation components that can install resources associated with your service applications. Installation components register an individual service on the system to which it is being installed and let the Services Control Manager know that the service exists. When you work with a service application, you can select a link in the Properties window to automatically add the appropriate installers to your project. For more information on installation components and how they work, see.
Property values for your service are copied from the service class to the installer class. If you update the property values on the service class, they are not automatically updated in the installer.
When you add an installer to your project, a new class (which, by default, is named ProjectInstaller) is created in the project, and instances of the appropriate installation components are created within it. This class acts as a central point for all of the installation components your project needs. For example, if you add a second service to your application and click the Add Installer link, a second installer class is not created; instead, the necessary additional installation component for the second service is added to the existing class.
You do not need to do any special coding within the installers to make your services install correctly. However, you may occasionally need to modify the contents of the installers if you need to add special functionality to the installation process. For more information, see.
After you add installers to your application, the next step is to create a setup project that will install the compiled project files and run the installers needed to install your service. To create a complete setup project, you must add the service project's output to the setup project and then add a custom action to have your service installed. For more information on setup projects, see. For more information on custom actions, see .
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see.
To add installers to your service application
In Solution Explorer, access Design view for the service for which you want to add an installation component.
Click the background of the designer to select the service itself, rather than any of its contents.
With the designer in focus, right-click, and then click Add Installer.
A new class, ProjectInstaller, and two installation components,and , are added to your project, and property values for the service are copied to the components.
Click the ServiceInstaller component and verify that the value of theproperty is set to the same value as the ServiceName property on the service itself.
To determine how your service will be started, click the ServiceInstaller component and set theproperty to the appropriate value.
The service must be manually started after installation. For more information, see.
The service will start by itself whenever the computer reboots.
The service cannot be started.
To determine the security context in which your service will run, click the ServiceProcessInstaller component and set the appropriate property values. For more information, see.
Override any methods for which you need to perform custom processing. For more information, see.
Perform steps 1 through 7 for each additional service in your project.
For each additional service in your project, you must add an additional ServiceInstaller component to the project's ProjectInstaller class. The ServiceProcessInstaller component added in step three works with all of the individual service installers in the project.
Create your setup project and custom action to deploy and install your service. For more information on setup projects, see. For more information on custom actions, see .