How to use Nuke.Build to install a .NET Sdk in GitHub Actions?

219 views Asked by At

How to use Nuke.Build to install a .NET Sdk in GitHub Actions?

  • Basically, I try to use Nuke.Build to setup GitHub Actions to build and test a Blazor project. The project uses the .NET 8 preview SDK. So, I will need to install the new SDK somehow.
  • But I don't know how to do it. I cannot find the instruction in the Nuke.Build documentation

Thank you for your help.

1

There are 1 answers

0
theogom On

When you setup Nuke using nuke :setup it generates some bootstraping scripts: build.cmd, build.ps1 and build.sh (see Nuke - Build setup - Project structure).

By default, these scripts determine the .NET version to use from a global.json file in the same directory and default to the STS channel if the file does not exists or no version is specified. So in your case you will want to have a global.json file that look like the following:

{
  "sdk": {
    "version": "8.0.100-rc.2.23502.2" // Specify the .NET SDK version you intend to use
  }
}

Then you will need to configure your targets to generate Github workflow files (see Nuke - GitHub Actions). After running your build with the nuke command you should see a line like this in the generated workflow file:

run: ./build.cmd Publish # 'Publish' will be replaced by your specific target(s)

This indicates that the bootstrapping script will be executed and set up the environment before running your target, including installing the desired .NET SDK version.