Skip to content
Latchkey

actions/setup-dotnet

Install the .NET SDK and optionally cache NuGet packages.

Official actionCategory: Language & Toolchain SetupLatest v4View on GitHub

What it does

actions/setup-dotnet installs the .NET SDK and puts dotnet on PATH. You can install several versions at once and pin the exact SDK via a global.json.

Enable NuGet caching with the cache input plus a lockfile, or via the built-in NuGet cache environment.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-dotnet@v4
    with:
      dotnet-version: '8.0.x'
  - run: dotnet test

Inputs

InputDescriptionDefaultRequired
dotnet-versionSDK version(s), e.g. 8.0.x. Multiple allowed.-No
global-json-filePath to a global.json pinning the SDK.-No
cacheEnable NuGet package caching.falseNo
cache-dependency-pathPath to packages.lock.json for the cache key.-No

Outputs

OutputDescription
dotnet-versionThe SDK version that was installed.
cache-hittrue if an exact NuGet cache was restored.

Notes

To cache NuGet packages with cache: true, commit a packages.lock.json (enable restore locking).

Common errors

  • A version like 8.0 that resolves to an unavailable SDK can fail; prefer 8.0.x or pin via global.json.
  • cache: true without a lockfile warns and does not cache. Enable NuGet lock files or point cache-dependency-path at one.

Security and pinning

  • Pin setup-dotnet to a commit SHA.

Frequently asked questions

How do I install multiple .NET versions?
Provide a multiline dotnet-version with each version on its own line; all are installed.
Running actions/setup-dotnet? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card