Subatomix.PowerShell.TaskHost 2.0.0-rc3

This is a prerelease version of Subatomix.PowerShell.TaskHost.
dotnet add package Subatomix.PowerShell.TaskHost --version 2.0.0-rc3
NuGet\Install-Package Subatomix.PowerShell.TaskHost -Version 2.0.0-rc3
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="Subatomix.PowerShell.TaskHost" Version="2.0.0-rc3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Subatomix.PowerShell.TaskHost --version 2.0.0-rc3
#r "nuget: Subatomix.PowerShell.TaskHost, 2.0.0-rc3"
#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 Subatomix.PowerShell.TaskHost as a Cake Addin
#addin nuget:?package=Subatomix.PowerShell.TaskHost&version=2.0.0-rc3&prerelease

// Install Subatomix.PowerShell.TaskHost as a Cake Tool
#tool nuget:?package=Subatomix.PowerShell.TaskHost&version=2.0.0-rc3&prerelease

About

The TaskHost PowerShell module and Subatomix.PowerShell.TaskHost NuGet package provide a thread-safe PowerShell PSHost wrapper to improve the clarity of output from long-running, possibly parallel tasks.

TaskHost adds a header to each line of output, reporting the elapsed time and which task produced the output. Line header components are optional and use color where supported.

Example output

Status

Build Build PSGallery PSGallery NuGet NuGet

  • Tested: 100% coverage by automated tests.
  • Documented: IntelliSense on everything. Quick-start guide below.

Installation

These instructions are for version 2.0 pre-releases. For version 1.0, see the prior version of these instructions.

From PowerShell 7 or later, install the TaskHost module:

Install-Module TaskHost -AllowPrerelease

Update or uninstall the module with Update-Module or Uninstall-Module, respectively.

Developers wanting to implement similar features in their own software can install the Subatomix.PowerShell.TaskHost NuGet package to get the building blocks of the TaskHost module.

Usage

These instructions are for version 2.0 pre-releases. For version 1.0, see the prior version of these instructions.

The Basics

Start with a Use-TaskHost command.

Use-TaskHost {
}

Optionally, add -WithElapsed to enable the elapsed-time header.

Use-TaskHost -WithElapsed {
}

For each task, add an Invoke-Task command.

Use-TaskHost -WithElapsed  {

    Invoke-Task "Step 1" {
        Write-Host "Example output from a task"
    }

    Invoke-Task "Step 2" {
        Write-Host "Example output from another task"
    }

}

Output:

[+00:00:00] [Step 1]: Example output from a task
[+00:00:00] [Step 2]: Example output from another task

A task is a chunk of code whose output should be distinguishable from that of other tasks and non-task code. Beyond that, what constitutes a task is entirely at the discretion of the user of this module. There is no restriction on the number of or size of tasks or on what can appear in a task's script block.

Tasks are nestable.

Use-TaskHost -WithElapsed  {
    Invoke-Task "Step 3" {

        Invoke-Task "Part 1" {
            Write-Host "Example output from a nested task"
        }

    }
}

Output:

[+00:00:00] [Step 3|Part 1]: Example output from a nested task

Advanced Usage

The PowerShell ForEach-Object -Parallel command complicates the preceding example. See this script for a working example with detailed explanation.

Information about the currently executing task is available via the following expression, which returns null if there is no such task:

[Subatomix.PowerShell.TaskHost.TaskInfo]::Current

The TaskInfo object provides a few useful properties:

  • Id – Unique integer identifier for the task.
  • Name – Name of the task. Writable.
  • FullNameName prefixed with the FullName of the task's parent, if any.
  • Parent – The task in which the current task is nested, if any.

The FullName property determines the text that TaskHost prepends to each output line. To change the text, set the Name property of the task or of its ancestors.

[Subatomix.PowerShell.TaskHost.TaskInfo]::Current.Name = "New name"

To remove the line header, set the property to an empty string.

[Subatomix.PowerShell.TaskHost.TaskInfo]::Current.Name = ""
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

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
2.0.0-rc3 82 10/13/2023
2.0.0-rc2 84 10/1/2023
2.0.0-rc1 96 9/9/2023
2.0.0-pre1 77 9/9/2023
2.0.0-pre0 94 9/9/2023
1.0.0 503 5/11/2022
1.0.0-rc.1 114 5/9/2022
1.0.0-pre.2 204 10/30/2021
1.0.0-pre.1 292 10/3/2021