ActionsToolkit.ToolCache 1.0.0

dotnet add package ActionsToolkit.ToolCache --version 1.0.0
                    
NuGet\Install-Package ActionsToolkit.ToolCache -Version 1.0.0
                    
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="ActionsToolkit.ToolCache" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ActionsToolkit.ToolCache" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ActionsToolkit.ToolCache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ActionsToolkit.ToolCache --version 1.0.0
                    
#r "nuget: ActionsToolkit.ToolCache, 1.0.0"
                    
#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.
#:package ActionsToolkit.ToolCache@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ActionsToolkit.ToolCache&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ActionsToolkit.ToolCache&version=1.0.0
                    
Install as a Cake Tool

ActionsToolkit.ToolCache package

To install the ActionsToolkit.ToolCache NuGet package:

<PackageReference Include="ActionsToolkit.ToolCache" Version="[Version]" />

Or use the dotnet add package .NET CLI command:

dotnet add package ActionsToolkit.ToolCache

Get the IToolCacheService instance

ActionsToolkit.ToolCache is the .NET equivalent of the official @actions/tool-cache Node package. It exposes IToolCacheService for downloading, extracting, caching, and resolving tools on a self-hosted or hosted runner. Register the service with an IServiceCollection by calling AddGitHubActionsToolCache() and consume IToolCacheService via constructor dependency injection.

using Microsoft.Extensions.DependencyInjection;
using ActionsToolkit.ToolCache;
using ActionsToolkit.ToolCache.Extensions;

using var provider = new ServiceCollection()
    .AddGitHubActionsToolCache()
    .BuildServiceProvider();

var toolCache = provider.GetRequiredService<IToolCacheService>();

The extension transitively registers ActionsToolkit.HttpClient so the IHttpClient used for downloads is fully resilient (Polly-backed).

Usage

The runner sets two environment variables that this package consults:

Variable Purpose
RUNNER_TOOL_CACHE Root directory of the on-disk tool cache (<tool>/<version>/<arch> layout).
RUNNER_TEMP Scratch directory used for intermediate downloads/extractions.

Download

var nodePath = await toolCache.DownloadToolAsync(
    "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.gz");

Extract

The .NET port uses SharpCompress for tar/tar.gz/tar.xz/tar.bz2/zstd/7z extraction (no native tar / 7z.exe shell-out is required). For zip the BCL System.IO.Compression is used.

var extracted = await toolCache.ExtractTarAsync(nodePath);
// or:
var extracted = await toolCache.ExtractZipAsync(zipPath);
var extracted = await toolCache.Extract7zAsync(sevenZipPath);

ExtractXarAsync throws PlatformNotSupportedException: SharpCompress does not ship xar support, so consumers should shell out to the native xar binary on macOS instead.

Cache

var cached = await toolCache.CacheDirAsync(extracted, "node", "20.10.0");
// or cache a single file (e.g. a downloaded GUID) under a friendly name:
var cached = await toolCache.CacheFileAsync(downloaded, "node.exe", "node", "20.10.0");

Find

var nodeDir = toolCache.Find("node", "20.x");
var allVersions = toolCache.FindAllVersions("node");

Versions manifest

var manifest = await toolCache.GetManifestFromRepoAsync(
    owner: "actions",
    repo: "node-versions",
    authToken: token,
    branch: "main");

var release = await toolCache.FindFromManifestAsync("20.x", stable: true, manifest);

Evaluate versions

var versions = new[] { "1.0.0", "1.2.3", "2.0.0", "3.0.1-beta" };
var match = toolCache.EvaluateVersions(versions, "1.x"); // "1.2.3"

Native AOT

The package is fully compatible with .NET Native AOT. JSON (de)serialization is driven entirely by source-generated JsonSerializerContexts — no reflection-based serializer overloads are called, no dynamic code is generated. A dedicated AOT smoke-test project (tests/ActionsToolkit.ToolCache.Aot.Tests) publishes a small consumer with <PublishAot>true</PublishAot> and exercises every public API to guard against IL2026/IL3050 regressions.

Attribution

This package is a .NET port of the official @actions/tool-cache Node.js package by GitHub, licensed under the MIT License.

Archive extraction is delegated to SharpCompress, licensed under the MIT License.

The npm-style semver subset is hand-rolled and modeled on node-semver, also under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.0.0 85 5/5/2026
1.0.0-rc.1 46 5/5/2026