From .NET Core 3, Windows Services are supported by the framework. Use https://www.nuget.org/packages/Microsoft.Extensions.Hosting.WindowsServices .
| Build server | Platform | Status |
|---|---|---|
| AppVeyor | Windows | |
| Travis | Linux |
The bare minimum for running a .NET Core 2 console app as a Windows Service. Currently, there's a NuGet for running ASP.NET Core apps as a Windows Service, but there's only a sample on how to do non web .NET Core apps as Windows Services. This NuGet extracts the code from that sample so it's more easily available.
> dotnet add package DotNetCore.WindowsServices
static async Task Main(string[] args)
{
var host = new HostBuilder();
host.ConfigureServices(c => c.AddSingleton<IHostedService, BackgroundWorker>());
await host.RunAsServiceAsync();
}
This will of course only work on Windows. Running it on another platform throws PlatformNotSupportedExceptions.