Plinth.WindowsService
1.5.0-b88.7a7c20cd
Prefix Reserved
See the version list below for details.
dotnet add package Plinth.WindowsService --version 1.5.0-b88.7a7c20cd
NuGet\Install-Package Plinth.WindowsService -Version 1.5.0-b88.7a7c20cd
<PackageReference Include="Plinth.WindowsService" Version="1.5.0-b88.7a7c20cd" />
<PackageVersion Include="Plinth.WindowsService" Version="1.5.0-b88.7a7c20cd" />
<PackageReference Include="Plinth.WindowsService" />
paket add Plinth.WindowsService --version 1.5.0-b88.7a7c20cd
#r "nuget: Plinth.WindowsService, 1.5.0-b88.7a7c20cd"
#:package Plinth.WindowsService@1.5.0-b88.7a7c20cd
#addin nuget:?package=Plinth.WindowsService&version=1.5.0-b88.7a7c20cd&prerelease
#tool nuget:?package=Plinth.WindowsService&version=1.5.0-b88.7a7c20cd&prerelease
README
Plinth.WindowsService
Makes creating a windows service easy
1. Install as service
- Include these in your csproj
<OutputType>Exe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
be sure to add the --urls {URLS} parameter to your binpath
- to run multiple ports, use semi-colon ';' between urls
--urls http://localhost:5050;https://something/
- note the usage of
SetContentRoot()when using your own IWebHost/IHost - windows services don't start with the current directory where your .exe is
- to run multiple ports, use semi-colon ';' between urls
Install >
sc create {ServiceName} displayName= "{DisplayName}" binpath= "D:\full\path\app.exe --urls http://localhost:9090" start= auto>sc description {ServiceName} "Service for Plinth WebApp"Change path or params after installing >
sc config {ServiceName} binPath= "{PathAndParams}"Delete service >
sc delete {ServiceName}Start/Stop >
net start {ServiceName}>net stop {ServiceName}
2. Standard ASP.NET Core project using NLog
- Program.cs [below]
- Add
--console --urls http://localhost:5050to your Debug settings as command line arguments- to run multiple ports, use semi-colon ';' between urls
--urls http://localhost:5050;https://something/
- to run multiple ports, use semi-colon ';' between urls
public class Program
{
public static void Main(string[] args)
{
var log = StaticLogManagerSetup.BasicNLogSetup();
log.Debug("startup!");
WindowsServiceRunner.RunWebHost(
BuildWebHost,
args,
callbacks: new Dictionary<ServiceState, Action>()
{
[ServiceState.Starting] = () => log.Debug("Starting..."),
[ServiceState.Started] = () => log.Debug("Started"),
[ServiceState.Stopping] = () => log.Debug("Stopping..."),
[ServiceState.Stopped] = () => log.Debug("Stopped"),
});
log.Debug("exit!");
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseContentRoot(WindowsServiceRunner.FindContentRoot()) // <==== REALLY IMPORTANT!
.ConfigureLogging(builder => builder.AddNLog())
.CaptureStartupErrors(false)
.Build();
}
3. Console project (no web interface), without NLog
- Program.cs [below]
- Add
--console --urls http://localhost:5050to your Debug settings as command line arguments- to run multiple ports, use semi-colon ';' between urls
--urls http://localhost:5050;https://something/
- to run multiple ports, use semi-colon ';' between urls
static void Main(string[] args)
{
var log = StaticLogManagerSetup.ConfigureForConsoleLogging();
log.Debug("startup!");
var mycallbacks = new Dictionary<ServiceState, Action>()
{
[ServiceState.Starting] = () => log.Debug("Main: Starting..."),
[ServiceState.Started] = () => log.Debug("Main: Started"),
[ServiceState.Stopping] = () => log.Debug("Main: Stopping..."),
[ServiceState.Stopped] = () => log.Debug("Main: Stopped"),
};
try
{
// option 1, make your own host and hosted service
// WindowsServiceRunner.RunHost(BuildHost, args, callbacks: mycallbacks);
// option 2, make your own hosted service
// WindowsServiceRunner.RunHostedService(new LoggerService(), args, callbacks: mycallbacks);
// option 3, a cancellable user action
// WindowsServiceRunner.RunAction(MyAction, args, callbacks: mycallbacks);
// option 4, a cancellable user action (async)
WindowsServiceRunner.RunAsyncAction(MyAsyncAction, args, callbacks: mycallbacks);
}
catch (Exception e)
{
log.Fatal("failed during startup", e);
throw;
}
}
// needed for option 1
public static IHost BuildHost(string[] args) =>
new HostBuilder()
.UseContentRoot(WindowsServiceRunner.FindContentRoot()) // <==== REALLY IMPORTANT!
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<LoggerService>();
})
.Build();
// needed for option 1 and option 2
public class LoggerService : IHostedService, IDisposable
{
private static readonly ILogger log = StaticLogManager.GetLogger();
public Task StartAsync(CancellationToken cancellationToken)
{
log.Debug("service start()");
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public void Dispose()
{
_timer?.Dispose();
}
}
// option 3
private static void MyAction(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
log.Debug("timer");
Task.Delay(TimeSpan.FromSeconds(2), token).Wait(); // try not to block on non cancellable calls
}
}
// option 4
private static async Task MyAsyncAction(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
log.Debug("timer");
await Task.Delay(TimeSpan.FromSeconds(2), token); // try not to block on non cancellable calls
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
-
net6.0-windows7.0
- Microsoft.AspNetCore.Hosting.WindowsServices (>= 6.0.11 && < 7.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.1 && < 7.0.0)
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.5.0-b88.7a7c20cd)
- Plinth.Logging.NLog (>= 1.5.0-b88.7a7c20cd)
-
net7.0-windows7.0
- Microsoft.AspNetCore.Hosting.WindowsServices (>= 7.0.0)
- Microsoft.Extensions.Hosting (>= 7.0.0)
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.5.0-b88.7a7c20cd)
- Plinth.Logging.NLog (>= 1.5.0-b88.7a7c20cd)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.8.0 | 270 | 11/13/2025 |
| 1.8.0-b211.72089fd9 | 223 | 11/12/2025 |
| 1.7.4 | 273 | 8/6/2025 |
| 1.7.3 | 85 | 8/2/2025 |
| 1.7.2 | 235 | 3/16/2025 |
| 1.7.1 | 198 | 12/12/2024 |
| 1.7.0 | 172 | 11/12/2024 |
| 1.6.6 | 167 | 11/8/2024 |
| 1.6.5 | 195 | 8/31/2024 |
| 1.6.4 | 174 | 8/2/2024 |
| 1.6.3 | 212 | 5/15/2024 |
| 1.6.2 | 227 | 2/16/2024 |
| 1.6.1 | 264 | 1/5/2024 |
| 1.6.0 | 252 | 11/30/2023 |
| 1.5.10-b186.aca976b4 | 134 | 11/30/2023 |
| 1.5.9 | 176 | 11/29/2023 |
| 1.5.9-b174.64153841 | 123 | 11/23/2023 |
| 1.5.9-b172.dfc6e7bd | 98 | 11/17/2023 |
| 1.5.9-b171.4e2b92e2 | 140 | 11/4/2023 |
| 1.5.8 | 185 | 10/23/2023 |
| 1.5.7 | 255 | 7/31/2023 |
| 1.5.6 | 233 | 7/13/2023 |
| 1.5.5 | 272 | 6/29/2023 |
| 1.5.4 | 383 | 3/7/2023 |
| 1.5.3 | 382 | 3/3/2023 |
| 1.5.2 | 446 | 1/11/2023 |
| 1.5.2-b92.7c961f5f | 205 | 1/11/2023 |
| 1.5.0 | 467 | 11/9/2022 |
| 1.5.0-b88.7a7c20cd | 212 | 11/9/2022 |
| 1.4.7 | 543 | 10/20/2022 |
| 1.4.6 | 548 | 10/17/2022 |
| 1.4.5 | 576 | 10/1/2022 |
| 1.4.4 | 529 | 8/16/2022 |
| 1.4.3 | 536 | 8/2/2022 |
| 1.4.2 | 561 | 7/19/2022 |
| 1.4.2-b80.7fdbfd04 | 244 | 7/19/2022 |
| 1.4.2-b74.acaf86f5 | 231 | 6/15/2022 |
| 1.4.1 | 588 | 6/13/2022 |
| 1.4.0 | 617 | 6/6/2022 |
| 1.3.8 | 597 | 4/12/2022 |
| 1.3.7 | 605 | 3/21/2022 |
| 1.3.6 | 620 | 3/17/2022 |
| 1.3.6-b67.ca5053f3 | 261 | 3/16/2022 |
| 1.3.6-b66.4a9683e6 | 260 | 3/16/2022 |
| 1.3.5 | 605 | 2/23/2022 |
| 1.3.4 | 639 | 1/20/2022 |
| 1.3.3 | 495 | 12/29/2021 |
| 1.3.2 | 630 | 12/11/2021 |
| 1.3.1 | 479 | 11/12/2021 |
| 1.3.0 | 494 | 11/8/2021 |
| 1.2.3 | 551 | 9/22/2021 |
| 1.2.2 | 538 | 8/20/2021 |
| 1.2.1 | 482 | 8/5/2021 |
| 1.2.0 | 528 | 8/1/2021 |
| 1.2.0-b37.a54030b9 | 280 | 6/24/2021 |
| 1.1.6 | 582 | 3/22/2021 |
| 1.1.5 | 545 | 3/9/2021 |
| 1.1.4 | 550 | 2/27/2021 |
| 1.1.3 | 582 | 2/17/2021 |
| 1.1.2 | 532 | 2/12/2021 |
| 1.1.1 | 568 | 2/1/2021 |
| 1.1.0 | 635 | 12/16/2020 |
| 1.1.0-b27.b66c309b | 416 | 11/15/2020 |
| 1.0.12 | 730 | 10/18/2020 |
| 1.0.11 | 651 | 10/6/2020 |
| 1.0.10 | 546 | 9/30/2020 |
| 1.0.9 | 579 | 9/29/2020 |
| 1.0.8 | 796 | 9/26/2020 |
| 1.0.7 | 750 | 9/19/2020 |
| 1.0.6 | 673 | 9/3/2020 |
| 1.0.5 | 669 | 9/2/2020 |
| 1.0.4 | 631 | 9/1/2020 |
| 1.0.3 | 680 | 9/1/2020 |
| 1.0.2 | 681 | 8/29/2020 |
| 1.0.1 | 697 | 8/29/2020 |
| 1.0.0 | 693 | 8/29/2020 |
| 1.0.0-b1.c22f563d | 388 | 8/28/2020 |
net7.0 support and removed netcoreapp3.1