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.sln
directly.
Edit the Worker.cs
file to implement your service logic.
dotnet run
Logs will appear in the terminal while running in console mode.
dotnet publish -c Release -o ./publish
The 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 MyService
Note
- 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
.