microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.45k stars 2.6k forks source link

[BUG]: UseDotNet@2 with global.json installs incorrect SDK version #20065

Open sander1095 opened 2 months ago

sander1095 commented 2 months ago

New issue checklist

Task name

UseDotNet

Task version

2

Issue Description

I'm using the following task:

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

with the following global.json

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

latestFeature should install the latest feature band version, meaning 8.0.xxx. At the time of writing, this is 8.0.302.

However, it installs 8.0.301, which is not desired. I am using latestFeature to ensure I always get the latest feature bands and security patches.

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows-Latest

Relevant log output

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

Full task logs with system.debug enabled

##[debug]adjustedPattern: 'D:\a\1\s\**/global.json'
##[debug]1 matches
##[debug]1 final results
##[debug]Agent environment resources - Disk: D:\ Available 12325.00 MB out of 14333.00 MB, Memory: Used 1972.00 MB out of 7167.00 MB, CPU: Usage 39.92%
##[debug]Finding channel 8.0 for version 8.0.301
Found version 8.0.301 in channel 8.0 for user specified version spec: 8.0.301
##[debug]Processed: ##vso[telemetry.publish area=TaskDeploymentMethod;feature=UseDotNetV2]{"userVersion":"8.0.301", "resolvedVersion":"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.
##[debug]which 'powershell'
##[debug]found: 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
##[debug]which 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
##[debug]found: 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe arg: -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command
##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe arg: & 'D:\a\_tasks\UseDotNet_b0ce7256-7898-45d3-9cb5-176b752bfea6\2.238.1\externals\get-os-platform.ps1'
##[debug]exec tool: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
##[debug]arguments:
##[debug]   -NoLogo
##[debug]   -Sta
##[debug]   -NoProfile
##[debug]   -NonInteractive
##[debug]   -ExecutionPolicy
##[debug]   Unrestricted
##[debug]   -Command
##[debug]   & 'D:\a\_tasks\UseDotNet_b0ce7256-7898-45d3-9cb5-176b752bfea6\2.238.1\externals\get-os-platform.ps1'
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
##[debug]Got download URL for platform with rid: win-x64
##[debug]isExplicit: 8.0.301
##[debug]explicit? true
Version 8.0.301 was not found in cache.
##[debug]
##[debug]Agent.Version=3.241.0
##[debug]Agent.TempDirectory=D:\a\_temp
##[debug]testing directory 'D:\a\_temp'
Downloading: https://download.visualstudio.microsoft.com/download/pr/7ac2d880-2d57-4008-850e-4b42b829c354/e1c92cb3b6a85f53cab6fa55b14b49e3/dotnet-sdk-8.0.301-win-x64.zip
##[debug]destination D:\a\_temp\b2f183bc-a169-4704-b09d-7fef1b4ff772
##[debug]downloading

Repro steps

name: $(major).$(minor)$(rev:.r)
trigger:
  branches:
    include:
    - main
  paths:
    exclude:
    - '**/*.md'

pool:
  vmImage: "windows-latest"

stages:
  - stage: build
    displayName: Build
    jobs:
      - job: Build_Code
        displayName: Build code
        steps:

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

I've also posted a question on StackOverflow to get some more assistance: https://stackoverflow.com/questions/78667998/why-is-azure-pipelines-installing-the-wrong-net-sdk-version-according-to-globa

sander1095 commented 2 months ago

The SO post has been answered. Apparently ,the .NET install task just installs the version specified and doesn't care about the rollForward. I feel like this could be improved, though