@@ -161,7 +161,7 @@ function Start-ScriptAnalyzerBuild
161161 # install the proper version
162162 Install-Dotnet
163163 if ( -not (Test-SuitableDotnet ) ) {
164- $requiredVersion = Get-GlobalJsonSdkVersion
164+ $requiredVersion = $ script :wantedVersion
165165 $foundVersion = Get-InstalledCLIVersion
166166 Write-Warning " No suitable dotnet CLI found, requires version '$requiredVersion ' found only '$foundVersion '"
167167 }
@@ -184,6 +184,7 @@ function Start-ScriptAnalyzerBuild
184184 {
185185 # Build all the versions of the analyzer
186186 foreach ($psVersion in 3 , 4 , 5 , 7 ) {
187+ Write-Verbose - Verbose - Message " Configuration: $Configuration PSVersion: $psVersion "
187188 Start-ScriptAnalyzerBuild - Configuration $Configuration - PSVersion $psVersion - Verbose:$verboseWanted
188189 }
189190 if ( $Catalog ) {
@@ -271,12 +272,17 @@ function Start-ScriptAnalyzerBuild
271272 $dotnetArgs += " ${PSScriptRoot} \bin\${buildConfiguration} \${framework} "
272273 }
273274 $buildOutput = & $script :DotnetExe $dotnetArgs 2>&1
274- if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
275+ if ( $LASTEXITCODE -ne 0 ) {
276+ Write-Verbose - Verbose - Message " dotnet is $ ( ${script :DotnetExe}.Source ) "
277+ $dotnetArgs | Foreach-Object {" dotnetArg: $_ " } | Write-Verbose - Verbose
278+ Get-PSCallStack | Write-Verbose - Verbose
279+ throw $buildOutput
280+ }
275281 Write-Verbose - Verbose:$verboseWanted - message " $buildOutput "
276282 }
277283 catch {
278- Write-Warning $_
279- Write-Error " Failure to build for PSVersion '$PSVersion ' using framework '$framework ' and configuration '$config '"
284+ $_ .TargetObject | Write-Warning
285+ Write-Error " Failure to build for PSVersion '$PSVersion ' using framework '$framework ' and configuration '$buildConfiguration '"
280286 throw
281287 }
282288 finally {
@@ -545,7 +551,7 @@ function ConvertTo-PortableVersion {
545551function Test-SuitableDotnet {
546552 param (
547553 $availableVersions = $ ( Get-InstalledCliVersion ),
548- $requiredVersion = $ ( Get-GlobalJsonSdkVersion )
554+ $requiredVersion = $script :wantedVersion
549555 )
550556
551557 if ( $requiredVersion -is [String ] -or $requiredVersion -is [Version ] ) {
@@ -610,7 +616,7 @@ function Get-InstalledCLIVersion {
610616function Test-DotnetInstallation
611617{
612618 param (
613- $requestedVersion = $ ( Get-GlobalJsonSdkVersion ) ,
619+ $requestedVersion = $script :wantedVersion ,
614620 $installedVersions = $ ( Get-InstalledCLIVersion )
615621 )
616622 return (Test-SuitableDotnet - availableVersions $installedVersions - requiredVersion $requestedVersion )
@@ -671,7 +677,8 @@ function Receive-DotnetInstallScript
671677
672678function Get-DotnetExe
673679{
674- $discoveredDotnet = Get-Command - CommandType Application dotnet - ErrorAction SilentlyContinu
680+ param ( $version = $script :wantedVersion )
681+ $discoveredDotnet = Get-Command - CommandType Application dotnet - ErrorAction SilentlyContinue - All
675682 if ( $discoveredDotnet ) {
676683 # it's possible that there are multiples. Take the highest version we find
677684 # the problem is that invoking dotnet on a version which is lower than the specified
@@ -682,13 +689,17 @@ function Get-DotnetExe
682689 # file points to a version of the sdk which is *not* installed. However, the format of the new list
683690 # with --version has a couple of spaces at the beginning of the line, so we need to be resilient
684691 # against that.
685- $latestDotnet = $discoveredDotNet |
686- Where-Object { try { & $_ -- version 2> $null } catch { } } |
687- Sort-Object { $pv = ConvertTo-PortableVersion (& $_ -- version 2> $null | % {$_.Trim ().Split()[0 ]}); " $pv " } |
692+ $properDotnet = $discoveredDotNet |
693+ Where-Object {
694+ & $_ -- list- sdks |
695+ Where-Object {
696+ $_ -match $version
697+ }
698+ } |
688699 Select-Object - Last 1
689- if ( $latestDotnet ) {
690- $script :DotnetExe = $latestDotnet
691- return $latestDotnet
700+ if ( $properDotnet ) {
701+ $script :DotnetExe = $properDotnet
702+ return $properDotnet
692703 }
693704 }
694705 # it's not in the path, try harder to find it by checking some usual places
@@ -714,6 +725,9 @@ function Get-DotnetExe
714725}
715726
716727try {
728+ # The version we want based on the global.JSON file
729+ # suck this before getting the dotnet exe
730+ $script :wantedVersion = Get-GlobalJsonSdkVersion - Raw
717731 $script :DotnetExe = Get-DotnetExe
718732}
719733catch {
0 commit comments