actions/setup-dotnet
Install the .NET SDK and optionally cache NuGet packages.
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 testInputs
| Input | Description | Default | Required |
|---|---|---|---|
dotnet-version | SDK version(s), e.g. 8.0.x. Multiple allowed. | - | No |
global-json-file | Path to a global.json pinning the SDK. | - | No |
cache | Enable NuGet package caching. | false | No |
cache-dependency-path | Path to packages.lock.json for the cache key. | - | No |
Outputs
| Output | Description |
|---|---|
dotnet-version | The SDK version that was installed. |
cache-hit | true 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.0that resolves to an unavailable SDK can fail; prefer8.0.xor pin via global.json. cache: truewithout a lockfile warns and does not cache. Enable NuGet lock files or pointcache-dependency-pathat 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.