Search code examples
c#.netazure-devopsazure-pipelinesazure-pipelines-build-task

Why is Azure Pipelines installing the wrong .NET SDK version (according to global.json)


I have a global.json that looks like this:

{
  "sdk": {
    "version": "8.0.301",
    "rollForward": "latestFeature"
  }
}

This means, as far as I know, that I want it to accept 8.0.xxx as long as it's not lower than 8.0.301. For example, both 8.0.302 and 8.0.400 would work, but 8.1.x or x.x.x wouldn't.

The problem is that my Azure Pipeline only wants to install 8.0.301. At the time of writing, 8.0.302 is available, which is backed up by Microsoft's official download page.

My Azure pipeline task that installs the .NET SDK is as follows:

- task: UseDotNet@2
  displayName: "Install .NET SDK"
    inputs:
      packageType: sdk
      useGlobalJson: true

But when this runs, I see the following logs:

Found version 8.0.301 in channel 8.0 for user specified version spec: 8.0.301
Getting URL to download .NET Core sdk version: 8.0.301.
Detecting OS platform to find correct download package for the OS.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'D:\a\_tasks\UseDotNet_b0ce7256-7898-45d3-9cb5-176b752bfea6\2.238.1\externals\get-os-platform.ps1'"
Primary:win-x64
Detected platform (Primary): win-x64
Version 8.0.301 was not found in cache.
Downloading: https://download.visualstudio.microsoft.com/download/pr/7ac2d880-2d57-4008-850e-4b42b829c354/e1c92cb3b6a85f53cab6fa55b14b49e3/dotnet-sdk-8.0.301-win-x64.zip
Extracting downloaded package D:\a\_temp\7024317f-ea64-4710-afa8-0435e0f177ed.
Extracting archive
C:\Windows\system32\chcp.com 65001
Active code page: 65001

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$ErrorActionPreference = 'Stop' ; try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('D:\a\_temp\7024317f-ea64-4710-afa8-0435e0f177ed', 'D:\a\_temp\9404')"

Successfully installed .NET Core sdk version 8.0.301.
Creating global tool path and pre-pending to PATH.
Finishing: Install .NET SDK

Why would it install 8.0.301 even though 8.0.302 should get downloaded?


For more information: https://github.com/microsoft/azure-pipelines-tasks/issues/20065


Solution

  • global.json and especially rollForward serve their own purpose:

    The global.json file allows you to define which .NET SDK version is used when you run .NET CLI commands.

    This is among already installed versions.

    The Use .NET V2 Task doesn't use global.json the same way:

    Use global json: This checkbox indicates that all versions from all global.json files will be used to install the sdk versions. You can set the search root path with Working Directory.

    Most likely it just looks for version numbers and does not reuse the version policy such as rollForward.

    In fact, since you are installing a .NET SDK, and not selecting which one of the installed ones to use for the CLI, it all makes sense.

    Maybe you should use the Version parameter of the task as suggested in the docs

    Version*: Specify version of .NET Core SDK or runtime to install. It also allows you to always get the latest version in a minor or major version. See below for examples Examples:

    To install 2.2.104 SDK, use 2.2.104
    To install 2.2.1 runtime, use 2.2.1
    To install 3.0.100-preview3-010431 sdk, use 3.0.100-preview3-010431
    To install latest patch version of 2.1 sdk, use 2.1.x
    To install latest minor version of 2. sdk, use 2.x
    For getting more details about exact version, refer this link.
    

    So for your use case, maybe use 8.0.3x. Experimentation is in order since the docs are not as clear with the band version.