How Do I Get .NET Preview Versions in GitHub Actions?

I wanted to setup a GitHub Action to build and test a .NET Preview project. Come in to read about how you can add a preview .NET version to your GitHub Action.

How Do I Get .NET  Preview Versions in GitHub Actions?

Short Version

Use the preview version's full name. For my example, I'll be using .NET 7 Preview 5:

- name: Setup dotnet
  uses: actions/setup-dotnet@v2
  with:
    dotnet-version: '7.0.100-preview.5.22307.18'

Feel free to use whichever preview version you desire (maybe even .NET 8+ if that's in preview when you're reading this ๐Ÿค”).

If you want to know where to get those long preview versions, read on below.

Long Version

I wanted to setup build and test checks for my project GameboyColour-Decolouriser:

GitHub - nikouu/GameboyColour-Decolouriser: Converts Gameboy Color images to the original 4 colours of the Gameboy
Converts Gameboy Color images to the original 4 colours of the Gameboy - GitHub - nikouu/GameboyColour-Decolouriser: Converts Gameboy Color images to the original 4 colours of the Gameboy

Normally when setting up a specific .NET version, you can use the tidy, normal version, such as this for .NET 6:

- name: Setup dotnet
  uses: actions/setup-dotnet@v2
  with:
    dotnet-version: '6.0'

See more with the .NET GitHub Action documentation.

However, with the preview versions not fully out, you must specify the exact version such as:

- name: Setup dotnet
  uses: actions/setup-dotnet@v2
  with:
    dotnet-version: '7.0.100-preview.5.22307.18'

Where do you get this version number? If you are using a preview version in your development environment, you can use the command:

dotnet --version
Result of dotnet --version.

Or, you can check what the latest full version is from the .NET download website. For example, to the .NET 7 downloads (at the time of writing this):

.NET 7 preview download page.

OR, if you want to check out what the bleeding edge is, you can head over to the tables in the dotnet installer repo, which are badged with the most recent builds.

.NET 7 bleeding edge installer table.

Putting this all together, whole .yml file I'm using for this project:

name: Build and Tests

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup dotnet
        uses: actions/setup-dotnet@v2
        with:
          dotnet-version: '7.0.100-preview.5.22307.18'
      - name: Install dependencies
        run: dotnet restore
      - name: Build
        run: dotnet build --configuration Release --no-restore
      - name: Test
        run: dotnet test --no-restore --verbosity normal

Which resulted in a successful run:

Successful .NET 7 Preview build and test.

To Conclude

I hope this helped you understand which .NET preview version you can add to your GitHub Action for building, testing, or whatever your needs may be ๐Ÿ˜.