Woof.ServiceInstaller 5.2.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Woof.ServiceInstaller --version 5.2.1
NuGet\Install-Package Woof.ServiceInstaller -Version 5.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Woof.ServiceInstaller" Version="5.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Woof.ServiceInstaller --version 5.2.1
#r "nuget: Woof.ServiceInstaller, 5.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Woof.ServiceInstaller as a Cake Addin
#addin nuget:?package=Woof.ServiceInstaller&version=5.2.1

// Install Woof.ServiceInstaller as a Cake Tool
#tool nuget:?package=Woof.ServiceInstaller&version=5.2.1

Woof.ServiceInstaller

.NET extension created by CodeDog

Distributed under MIT License. (c)2021 by CodeDog, All rights reserved.


About

Installs and runs systems services. Works both on Windows and Linux. On Linux uses systemd.

For help use dotnet {command} --help. To install: sudo dotnet {command} --install To uninstall: sudo dotnet {command} --uninstall To delete Windows Event Log: {command} --delete-log (administrator required)

This package uses Woof.CommandLine package to handle the command line arguments with POSIX syntax guidelines.

Usage

Given:

  • ClientService is your service class implementing IHostedService,
  • Config.Data contains your service metadata class instance implementing IConfiguration

Here's example Main mehtod:

private async static Task<int> Main(string[] args) {
    var commandLine = CommandLine.Default; // default CommandLine instance
    ServiceInstaller.Configure<ClientService>(Config.Data); // required
    if (ServiceInstaller.ServiceMetadata is null) throw new NullReferenceException();
    if (args?.Length > 0) { // run only when arguments present (not as service)
        commandLine.Map<Options>(); // optional additional options
        commandLine.Delegates.Add(Options.Help, Help); // optional additional delegates
        commandLine.Parse(args); // required
        var errors = CommandLine.ValidationErrors;
        if (errors is not null) Error(errors); // optionally show errors if any
        else await commandLine.RunDelegatesAsync(); // required
    }
    else
        await ServiceController
            .RunHostAsync<ClientService>(ServiceInstaller.ServiceMetadata!);
            // required
    return 0;
}

To execute code before or after installation / uninstallation simply check if the install/uninstall options are present before and/or after RunDelegatesAsync like this:

if (commandLine.HasOption(ServiceInstaller.Options.Install)) {
    // code to execute
}

The installed service is started with

ServiceController.RunHostAsync<ClientService>(ServiceInstaller.ServiceMetadata!);

If executing of some external commands is needed before or after the installation, ServiceController.ExecAsync method can be used for that. If the command executed that way fails, the method will throw an InvalidOperationException with the error message obtained from the command output.

For more information see the included example project.

Compatibility

The package is compatible with .NET Standard 2.1 and .NET 5.0 or newer. The applications using the module can run both on Windows and Linux.


Disclaimer

Please report any issues to the toolkit developer.

Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
7.0.0 211 8/6/2023
6.2.0 501 2/20/2022
6.1.4 1,385 11/28/2021
6.1.3 255 11/27/2021
6.1.2 1,828 11/26/2021
6.0.5 2,356 11/25/2021
6.0.4 277 11/17/2021
6.0.3 267 11/15/2021
6.0.2 356 11/12/2021
6.0.1 363 11/11/2021
5.2.7 395 11/1/2021
5.2.6 443 10/30/2021
5.2.5 409 10/20/2021
5.2.4 403 10/20/2021
5.2.3 359 10/20/2021
5.2.2 358 10/15/2021
5.2.1 363 10/14/2021
5.2.0 425 10/14/2021
5.1.1 392 10/13/2021
5.1.0 401 10/12/2021
5.0.3 369 8/27/2021
5.0.2 410 8/27/2021
5.0.1 399 8/20/2021
5.0.0 367 8/19/2021

ADD: DeleteLog option is available only for Windows.