A minimal and clean template to help you create a Windows Service in .NET
git clone https://github.com/sanamhub/dotnet-windows-service.git
cd dotnet-windows-service-
With VS Code
code . -
Or with Visual Studio (if installed) Open
WindowsService.slndirectly.
Edit the Worker.cs file to implement your service logic.
dotnet runLogs will appear in the terminal while running in console mode.
dotnet publish -c Release -o ./publishThe output will be located in the publish folder.
sc.exe create MyService binPath= "C:\path\to\your\project\publish\WindowsService.exe"Important
🛑 Replace the path with your actual publish folder path.
sc.exe delete MyServiceNote
- Always run the command prompt as Administrator when installing or uninstalling the service.
- You can manage the service using
services.msc(Start, Stop, Restart). - Customize logging, interval, or behavior inside
Worker.cs.