How to Set Up a Specific .NET Version on Windows in GitHub Actions
actions/setup-dotnet installs an exact SDK band, and you can list several for multi-target builds.
Pass dotnet-version (a single value or a multiline list) to actions/setup-dotnet. Multiple values install side by side so a multi-target solution finds each SDK.
Steps
- Add
actions/setup-dotnetwith adotnet-versionband such as8.0.x. - List several versions on separate lines to install them side by side.
- Verify with
dotnet --list-sdksbefore building.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
- run: dotnet --list-sdks
- run: dotnet build --configuration ReleaseGotchas
- A
global.jsoncan pin the SDK and override what the action selects; keep them consistent. - Hosted images preinstall several SDKs, but the action guarantees the exact version your build expects.
Related guides
How to Build a .NET App on Windows in GitHub ActionsBuild and test a .NET application on a windows-latest runner in GitHub Actions with actions/setup-dotnet, dot…
How to Set Up Python on Windows in GitHub ActionsInstall a specific Python on a windows-latest runner in GitHub Actions with actions/setup-python, enabling pi…