I\'m trying to build a Windows Service in .Net Core 2.0 but I\'ve been banging my head on the wall for a full day and no progress at all. Everything seems to be using Core 1.0/1
We just need System.ServiceProcess.ServiceController NuGet package to run a .NET Core application as Windows Service.
Following is the .csproj file,
Exe
netcoreapp2.1
win7-x64
Program.cs file,
using System.ServiceProcess;
namespace WindowsService101
{
class Program
{
static void Main(string[] args)
{
using (var service = new HelloWorldService())
{
ServiceBase.Run(service);
}
}
}
}
public class HelloWorldService : ServiceBase
{
protected override void OnStart(string[] args)
{
// Code Here
}
protected override void OnStop()
{
// Code Here
}
}
Build and Publish the solution.
Open Cmd Prompt in Admin mode from the .exe folder Sample: \WindowsService101\bin\Debug\netcoreapp2.1\publish
sc create binPath=""
sc start