@@ -161,7 +161,7 @@ function Start-ScriptAnalyzerBuild
161
161
# install the proper version
162
162
Install-Dotnet
163
163
if ( -not (Test-SuitableDotnet ) ) {
164
- $requiredVersion = Get-GlobalJsonSdkVersion
164
+ $requiredVersion = $ script :wantedVersion
165
165
$foundVersion = Get-InstalledCLIVersion
166
166
Write-Warning " No suitable dotnet CLI found, requires version '$requiredVersion ' found only '$foundVersion '"
167
167
}
@@ -184,6 +184,7 @@ function Start-ScriptAnalyzerBuild
184
184
{
185
185
# Build all the versions of the analyzer
186
186
foreach ($psVersion in 3 , 4 , 5 , 7 ) {
187
+ Write-Verbose - Verbose - Message " Configuration: $Configuration PSVersion: $psVersion "
187
188
Start-ScriptAnalyzerBuild - Configuration $Configuration - PSVersion $psVersion - Verbose:$verboseWanted
188
189
}
189
190
if ( $Catalog ) {
@@ -271,12 +272,17 @@ function Start-ScriptAnalyzerBuild
271
272
$dotnetArgs += " ${PSScriptRoot} \bin\${buildConfiguration} \${framework} "
272
273
}
273
274
$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
+ }
275
281
Write-Verbose - Verbose:$verboseWanted - message " $buildOutput "
276
282
}
277
283
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 '"
280
286
throw
281
287
}
282
288
finally {
@@ -545,7 +551,7 @@ function ConvertTo-PortableVersion {
545
551
function Test-SuitableDotnet {
546
552
param (
547
553
$availableVersions = $ ( Get-InstalledCliVersion ),
548
- $requiredVersion = $ ( Get-GlobalJsonSdkVersion )
554
+ $requiredVersion = $script :wantedVersion
549
555
)
550
556
551
557
if ( $requiredVersion -is [String ] -or $requiredVersion -is [Version ] ) {
@@ -610,7 +616,7 @@ function Get-InstalledCLIVersion {
610
616
function Test-DotnetInstallation
611
617
{
612
618
param (
613
- $requestedVersion = $ ( Get-GlobalJsonSdkVersion ) ,
619
+ $requestedVersion = $script :wantedVersion ,
614
620
$installedVersions = $ ( Get-InstalledCLIVersion )
615
621
)
616
622
return (Test-SuitableDotnet - availableVersions $installedVersions - requiredVersion $requestedVersion )
@@ -671,7 +677,8 @@ function Receive-DotnetInstallScript
671
677
672
678
function Get-DotnetExe
673
679
{
674
- $discoveredDotnet = Get-Command - CommandType Application dotnet - ErrorAction SilentlyContinu
680
+ param ( $version = $script :wantedVersion )
681
+ $discoveredDotnet = Get-Command - CommandType Application dotnet - ErrorAction SilentlyContinue - All
675
682
if ( $discoveredDotnet ) {
676
683
# it's possible that there are multiples. Take the highest version we find
677
684
# the problem is that invoking dotnet on a version which is lower than the specified
@@ -682,13 +689,17 @@ function Get-DotnetExe
682
689
# file points to a version of the sdk which is *not* installed. However, the format of the new list
683
690
# with --version has a couple of spaces at the beginning of the line, so we need to be resilient
684
691
# 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
+ } |
688
699
Select-Object - Last 1
689
- if ( $latestDotnet ) {
690
- $script :DotnetExe = $latestDotnet
691
- return $latestDotnet
700
+ if ( $properDotnet ) {
701
+ $script :DotnetExe = $properDotnet
702
+ return $properDotnet
692
703
}
693
704
}
694
705
# it's not in the path, try harder to find it by checking some usual places
@@ -714,6 +725,9 @@ function Get-DotnetExe
714
725
}
715
726
716
727
try {
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
717
731
$script :DotnetExe = Get-DotnetExe
718
732
}
719
733
catch {
0 commit comments