From a63973c39ccedbd1d73e21170d96813abde18ba9 Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Fri, 14 Nov 2025 10:27:34 -0800 Subject: [PATCH] Refactor vsRequirements assignment logic in tools.ps1 Because 17.14 went stable, we needed a way to run vswhere, find the VS node, and enable preview SDKs. Noah found a way to do this but he had to modify tools.ps1 because the SDK repo didn't have a VS node in our global.json https://github.com/dotnet/sdk/pull/51558/files#diff-72b8f8e899b94872c6ead31fd06ec109da15bcb9ad2af6e78103d6763a31c637 Porting his change here to see if folks want this centrally. Alternatively, I'm trying adding the vs node to global.json to see if it unblocks us. --- eng/common/tools.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index 9b3ad8840fd..b4cc83b46e3 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -547,19 +547,26 @@ function LocateVisualStudio([object]$vsRequirements = $null){ }) } - if (!$vsRequirements) { $vsRequirements = $GlobalJson.tools.vs } + if (!$vsRequirements) { + if (Get-Member -InputObject $GlobalJson.tools -Name 'vs' -ErrorAction SilentlyContinue) { + $vsRequirements = $GlobalJson.tools.vs + } else { + $vsRequirements = $null + } + } + $args = @('-latest', '-format', 'json', '-requires', 'Microsoft.Component.MSBuild', '-products', '*') if (!$excludePrereleaseVS) { $args += '-prerelease' } - if (Get-Member -InputObject $vsRequirements -Name 'version') { + if ($vsRequirements -and (Get-Member -InputObject $vsRequirements -Name 'version' -ErrorAction SilentlyContinue)) { $args += '-version' $args += $vsRequirements.version } - if (Get-Member -InputObject $vsRequirements -Name 'components') { + if ($vsRequirements -and (Get-Member -InputObject $vsRequirements -Name 'components' -ErrorAction SilentlyContinue)) { foreach ($component in $vsRequirements.components) { $args += '-requires' $args += $component