Although you can easily
create batch files to install a service, at times you might want to
carry out more sophisticated actions than a batch file allows.
Microsoft Visual
Studio 2008 provides you with the ability to create a setup project by
either using the setup project template or by using the setup project
wizard.
Adding the Setup Project
The first thing we need to do is create the setup project. Open your tutorials
solution. Right-click the solution, choose Add, and then select New
Project. From the Project Template dialog box, expand Other Project
Types, select Setup And Deployment, and then select Setup Project.
Select the Setup Project,
not the Setup Wizard. I have left my setup project named setup1. After
we add the setup project to the solution, we need to configure it.
Add the Project Output
Right-click
the setup1 project, select Add, select Project Output, and then select
Primary Output. Click OK. This will add the exe and dependencies of your
service.
Note
If
you are in the debug configuration, the output will be from the debug
folder; if you are in the release, it will be from the release folder. |
Now we need to create a custom action that will install the service.
Creating Custom Actions
Custom actions
define how and what a setup program does. For our project, we need to
install the service and the debug symbols. Your service may have other
things to include, such as resource files, bitmaps, or configuration
files.
Creating a Service Custom Action
First, we want to create
the output that will build and install the service. Right-click the
setup1 project again, and this time choose View and then choose Custom
Actions. Click OK. Right-click Custom Actions. From the pop-up menu,
select Add Custom Action. Select Application Folder and then click OK.
Select Primary Output From Tutorials (Active) and click OK.
Creating a Debug Symbol Custom Action
Next, we want to add
debug symbols. Right-click the setup1 project, select Add, and then
select Project Output. Select Debug Symbols and click OK. Now the
service and the debug symbols are ready to be installed.
Adding a Configuration File
Right-click the
setup1 project again, choose Add, and then choose File. Browse to where
your configurations file is, select it, and click OK. You will notice
that the file is now added to your project. Right-click the file and
choose Properties, or double-click to open the file for editing. In the
Properties window, you can change the output target name, location, and
several other important attributes of the file when it is installed on
the user or server computer.
Testing the Setup Project
To test the project,
right-click the setup1 project and choose Build. By default, the setup
project will not build each time you build the solution.
After you build the
setup program, open Windows Explorer and browse to the generated
setup1.msi file, right-click it, and select Install from the pop-up
menu. The service will now be installed. You can verify installation by
going to the Services window and verifying that you see
the service listed. If you want to uninstall the service, you can use
Add/Remove Programs or go back to your msi package, right-click it, and
select Uninstall.
Note
If
you need custom security settings or other things included with your
project, review the MSDN documentation for creating setup projects. |