How do you automatically start a service after running an install from a Visual Studio Setup Project?
I just figured this one out and thought I would share the answe
This approach uses the Installer class and the least amount of code.
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
namespace MyProject
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
serviceInstaller1.AfterInstall += (sender, args) => new ServiceController(serviceInstaller1.ServiceName).Start();
}
}
}
Define serviceInstaller1
(type ServiceInstaller) in the Installer class designer and also set its ServiceName
property in the designer.