'Get UseDotNet@2 in Azure DevOps to use the vmImage's dotnet SDK (or one from a cache)
I have an Azure DevOps pipeline with an agent and step like this:
pool:
vmImage: 'windows-latest'
# ....
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '5.x'
The agent resolves to Windows 2022 and MSDN links to this list of installed software which includes 5.0.406 as the latest 5.x version of dotnet. So, I would presume the step would see that the software is already available and not do anything.
Instead, the step takes 25 seconds to do download it anyways? Here's the output from Azure DevOps:
2022-03-31T09:32:37.5205829Z ##[section]Starting: UseDotNet
2022-03-31T09:32:37.5326189Z ==============================================================================
2022-03-31T09:32:37.5326523Z Task : Use .NET Core
2022-03-31T09:32:37.5327080Z Description : Acquires a specific version of the .NET Core SDK from the internet or the local cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks. Additionally provides proxy support.
2022-03-31T09:32:37.5327618Z Version : 2.198.0
2022-03-31T09:32:37.5327838Z Author : Microsoft Corporation
2022-03-31T09:32:37.5328057Z Help : https://aka.ms/AA4xgy0
2022-03-31T09:32:37.5328346Z ==============================================================================
2022-03-31T09:32:38.1175143Z Tool to install: .NET Core sdk version 5.x.
2022-03-31T09:32:40.3450298Z Found version 5.0.406 in channel 5.0 for user specified version spec: 5.x
2022-03-31T09:32:40.3901604Z Version 5.0.406 was not found in cache.
2022-03-31T09:32:40.3902218Z Getting URL to download .NET Core sdk version: 5.0.406.
2022-03-31T09:32:40.3903044Z Detecting OS platform to find correct download package for the OS.
2022-03-31T09:32:40.3919001Z [command]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.198.0\externals\get-os-platform.ps1'"
2022-03-31T09:32:40.7335953Z Primary:win-x64
2022-03-31T09:32:40.7337064Z Detected platform (Primary): win-x64
2022-03-31T09:32:40.7357212Z Downloading: https://download.visualstudio.microsoft.com/download/pr/aa30e704-a085-4ed4-bcbd-9f3491b7722b/05a1aefc5c841a1faa7eae08a5cec110/dotnet-sdk-5.0.406-win-x64.zip
2022-03-31T09:32:42.0180110Z Extracting downloaded package D:\a\_temp\33032e6d-ebd8-4f81-951e-779d5384477e.
2022-03-31T09:32:42.0188915Z Extracting archive
2022-03-31T09:32:42.0229477Z [command]C:\Windows\system32\chcp.com 65001
2022-03-31T09:32:42.0330177Z Active code page: 65001
2022-03-31T09:32:42.0554435Z [command]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\33032e6d-ebd8-4f81-951e-779d5384477e', 'D:\a\_temp\99ba')"
2022-03-31T09:33:02.8364659Z Successfully installed .NET Core sdk version 5.0.406.
2022-03-31T09:33:02.8381246Z Creating global tool path and pre-pending to PATH.
2022-03-31T09:33:02.8488020Z ##[section]Finishing: UseDotNet
How can I ensure that my dotnet SDK is being grabbed from the vmImage's installed software or from some kind of cache? I'd love to get those 25 seconds back in my builds...
Solution 1:[1]
At the time of writing it seems this is an open issue in Azure Devops, incidentally only weeks before this Stack Overflow question was created one user commented on GitHub:
Downloading .NET 5.x takes 30 seconds while it's already on the windows-latest image. This costs us time, and it costs Microsoft precious server resources.
Which seems to be exactly the same issue.
I'm posting this "answer" for visibility. Perhaps others (a) can post workarounds in answers, or (b) in the future a real answer can be added?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeroen |
