Skip to content
Latchkey

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-dotnet with a dotnet-version band such as 8.0.x.
  • List several versions on separate lines to install them side by side.
  • Verify with dotnet --list-sdks before 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 Release

Gotchas

  • A global.json can 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

Run this faster and cheaper on Latchkey managed runners. Start free →