Skip to content

Commit 183f334

Browse files
committed
v2.0.1: add symbols and (more) documentation
2 parents 78587be + ce72f39 commit 183f334

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

.github/workflows/Publish-Package.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ jobs:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3636
with:
3737
fail_on_unmatched_files: true # needs action-gh-release@v2 but that doesn't exist yet, gives a warning now
38-
files: '**/*.nupkg'
38+
files: |
39+
**/*.nupkg
40+
**/*.snupkg
3941
4042
- name: Release to NuGet.org
4143
if: startsWith(github.ref, 'refs/tags/')
42-
run: nuget push **/*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}} -NoSymbols
44+
run: nuget push **/*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}

Readme.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# WindowsServiceExtensions
2-
Make a .NET Core Windows Service that runs `IHostedService` background services power event aware.
2+
Make a .NET Core Windows Service that runs `IHostedService` background services power event aware. On consumer OS Windows 10, shutting down the computer will actually hibernate the OS. Services won't get another OnStart call.
33

4-
On consumer OS Windows 10, shutting down the computer will actually hibernate the OS. Services won't get another OnStart call.
4+
This project exists of a few classes that make building reliable Windows Services easier. The Lifetime class also include [kmcclellan's fixes](https://github.com/dotnet/runtime/issues/50019#issuecomment-678658133) that make the service throw when something fails on startup, instead of reprorting it started successfully.
55

6-
These extensions allow your IHostedServices to respond to this power state change:
6+
## Installation
7+
Through [NuGet](https://www.nuget.org/packages/CodeCaster.WindowsServiceExtensions/):
8+
9+
> Install-Package CodeCaster.WindowsServiceExtensions
10+
11+
## Usage
12+
These extensions allow your IHostedServices to respond to this power state change.:
713

814
* On your Host Builder, call `UsePowerEventAwareWindowsService()` instead of [`UseWindowsService()`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.windowsservicelifetimehostbuilderextensions.usewindowsservice?view=dotnet-plat-ext-3.1).
915
* Instead of letting your service inherit [`Microsoft.Extensions.Hosting.BackgroundService`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.backgroundservice?view=dotnet-plat-ext-5.0), inherit from `CodeCaster.WindowsServiceExtensions.PowerEventAwareBackgroundService`.
10-
* Implement the method `public override bool OnPowerEvent(PowerBroadcastStatus powerStatus)`
16+
* Implement the method `public override bool OnPowerEvent(PowerBroadcastStatus powerStatus)` and do your thing when it's called with a certain status.
1117

1218
Do note that the statuses received can vary. You get either `ResumeSuspend`, `ResumeAutomatic` or both, never neither, after a machine wake, reboot or boot.

src/CodeCaster.WindowsServiceExtensions/CodeCaster.WindowsServiceExtensions.csproj

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
6+
7+
<Version>2.0.1</Version>
8+
<PackageId>CodeCaster.WindowsServiceExtensions</PackageId>
9+
<PackageTags>Windows Service;Power event;IHostedService;BackgroundService;</PackageTags>
10+
611
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
7-
<PackageProjectUrl>https://github.com/CodeCasterNL/WindowsServiceExtensions</PackageProjectUrl>
12+
<IncludeSymbols>true</IncludeSymbols>
13+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
14+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15+
816
<RepositoryUrl>https://github.com/CodeCasterNL/WindowsServiceExtensions</RepositoryUrl>
9-
<RepositoryType>GitHub</RepositoryType>
10-
<PackageTags></PackageTags>
17+
<RepositoryType>git</RepositoryType>
18+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1119
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
12-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
20+
1321
<Authors>CodeCaster</Authors>
14-
<Company />
15-
<Copyright>CodeCaster</Copyright>
22+
<Company>CodeCaster</Company>
23+
<Copyright>© 2021 CodeCaster</Copyright>
1624
<Description>Makes your .NET 5 BackgroundServices power-event-aware.</Description>
17-
<Version>2.0.0</Version>
1825
</PropertyGroup>
1926

2027
<ItemGroup>
2128
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
2229
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
2330
</ItemGroup>
2431

25-
<ItemGroup>
26-
<None Include="..\..\LICENSE">
27-
<Pack>True</Pack>
28-
<PackagePath></PackagePath>
29-
</None>
30-
</ItemGroup>
31-
3232
</Project>

src/CodeCaster.WindowsServiceExtensions/PowerEventAwareWindowsServiceLifetime.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PowerEventAwareWindowsServiceLifetime : WindowsServiceLifetime, IHo
2525
private readonly IHostApplicationLifetime _applicationLifetime;
2626
private IReadOnlyCollection<IPowerEventAwareHostedService>? _hostedServices;
2727

28+
/// <inheritdoc />
2829
public PowerEventAwareWindowsServiceLifetime(IServiceProvider serviceProvider, IHostEnvironment environment, IHostApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory, IOptions<HostOptions> optionsAccessor)
2930
: base(environment, applicationLifetime, loggerFactory, optionsAccessor)
3031
{
@@ -38,6 +39,7 @@ public PowerEventAwareWindowsServiceLifetime(IServiceProvider serviceProvider, I
3839
}
3940
}
4041

42+
/// <inheritdoc />
4143
public new async Task WaitForStartAsync(CancellationToken cancellationToken)
4244
{
4345
_logger.LogInformation("Windows Service start requested");
@@ -88,6 +90,7 @@ protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
8890
return true;
8991
}
9092

93+
/// <inheritdoc />
9194
protected override void OnStart(string[] args)
9295
{
9396
_logger.LogInformation("Windows Service OnStart() was called");

0 commit comments

Comments
 (0)