Install service via Installer
Hi all,
I have a Windows Service project, and an Installer project to create a .MSI for it. I'd like for the MSI to install the service after it is done installing the project. I think I need to do this with a Commit Custom Action, but cannot figure out how.
Seems like this should be easy, and common, right?
Thanks for any input.
Cheers,
Chris
You need to create a new service installer, this is a class with the RunInstaller attribute and that inherits from System.Configuration.Install.Installer. This then ads an array of System.Configuration.Install.Installer[] to its Installers property - e.g. - a ServiceProcessinstaller and ServiceInstaller.
If you used a wizard to make the service you can get away with Add Installer with the file selected in solution explorer! Look in the small panel at the bottom of the properties view.
Here's a quick example:
using System;
using
System.Collections; using
System.Configuration.Install; namespace
Example {
/// <summary> /// An example installer /// </summary> [RunInstaller(
true)] public class ServiceProjectInstaller : System.Configuration.Install.Installer {
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller; private System.ServiceProcess.ServiceInstaller serviceInstaller; public ServiceProjectInstaller() {
serviceProcessInstaller =
new System.ServiceProcess.ServiceProcessInstaller(); serviceInstaller =
new System.ServiceProcess.ServiceInstaller(); serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
serviceProcessInstaller.Password =
null; serviceProcessInstaller.Username =
null; serviceInstaller.DisplayName =
"My Service"; serviceInstaller.ServiceName =
"MyService"; serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
serviceInstaller.ServicesDependedOn =
new string[] { "Netman", "Eventlog", "Workstation" }; //any other stuff goes in here Installers.AddRange(
new System.Configuration.Install.Installer[] { this.serviceProcessInstaller, this.serviceInstaller }); }
}
}
Hi Simon,
Thanks for the reply. I already have a service project with the Service and Process Installers in it. The .exe that is built by this project still needs to be installed on the system using InstallUtil.exe. It is this process that I am trying to automate in the deployment Setup Project (the output .MSI).
Am I missing something in what you responded with?
Cheers,
Chris
Sorry, I should have said - from memory you just need to add a custom action to the install action set to the primary output of the project/the file with the installer in.
I don't have my projects to hand on this computer, but I don't think you need to set up commit, rollback or uninstall actions: these are automatic.
If you can control the contents of your MSI there are some tables you can use. See this post by Phil Wilson in microsoft.public.dotnet.framework.setup (sorry for the long URL)
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.setup/browse_frm/thread/546693a8d0da98f/91d5cd81057ead44?q=tthe+%22phil+wilson%22+group:microsoft.public.dotnet.framework.setup&rnum=3#91d5cd81057ead44
wrote in message news:4c33b117-9fdf-4603-8a33-97500abe0a87@discussions.microsoft.com... Hi all,
I have a Windows Service project, and an Installer project to create a ..MSI for it. I'd like for the MSI to install the service after it is done installing the project. I think I need to do this with a Commit Custom Action, but cannot figure out how.
Seems like this should be easy, and common, right?
Thanks for any input.
Cheers,
Chris
not sure if you still need this but i eventually worked it out.
add an install package project to your solution.
add to this the the primary output from yourt service.
right-click the setup package project, choose View --> Custom Actions
add the Primary Output from the service project under each of the headings... Commit, Install, Rollback etc.