I created an ASP.NET Core Windows Service application using this sample: https://github.com/dotnet/AspNetCore.Docs/tree/master/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService
Now, I want to install my service using command line, like "MyService.exe -install". I know that if I use "sc create" will works, but I want to install using my own application to install and configure the service as I want.
I found a sample using Toshelf package, but I am using WebHostBuilder and I trying to use Custom Service configuration. The service install, but when I start it doesn`t work.
I am using .NET Core 2.2.
My configuration:
HostFactory.Run(x =>
{
x.Service<CustomWebHostService>(sc =>
{
sc.ConstructUsing(() => new CustomWebHostService(host));
// the start and stop methods for the service
sc.WhenStarted(ServiceBase.Run);
sc.WhenStopped(s => s.Stop());
});
x.RunAsLocalSystem();
x.StartAutomatically();
x.SetServiceName("Teste Core");
x.SetDisplayName("Teste ASP.NET Core Service");
x.SetDescription("Teste ASP.NET Core as Windows Service.");
});
My full source code: https://github.com/rkiguti/dotnetcore.windows-service