@@ -130,7 +130,8 @@ function Start-ScriptAnalyzerBuild
130
130
# don't allow the build to be started unless we have the proper Cli version
131
131
if ( -not (Test-SuitableDotnet ) ) {
132
132
$requiredVersion = Get-GlobalJsonSdkVersion
133
- throw " No suitable dotnet CLI found, requires version '$requiredVersion '"
133
+ $foundVersion = Get-InstalledCLIVersion
134
+ throw " No suitable dotnet CLI found, requires version '$requiredVersion ' found only '$foundVersion '"
134
135
}
135
136
}
136
137
END {
@@ -201,7 +202,7 @@ function Start-ScriptAnalyzerBuild
201
202
try {
202
203
Push-Location $projectRoot / Rules
203
204
Write-Progress " Building ScriptAnalyzer for PSVersion '$PSVersion ' using framework '$framework ' and configuration '$Configuration '"
204
- $buildOutput = dotnet build -- framework $framework -- configuration " $config "
205
+ $buildOutput = & $ script :dotnetExe build -- framework $framework -- configuration " $config "
205
206
if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
206
207
}
207
208
catch {
@@ -285,7 +286,7 @@ function Get-TestFailures
285
286
function Install-Dotnet
286
287
{
287
288
[CmdletBinding (SupportsShouldProcess = $true )]
288
- param (
289
+ param (
289
290
[Parameter ()][Switch ]$Force ,
290
291
[Parameter ()]$version = $ ( Get-GlobalJsonSdkVersion )
291
292
)
@@ -363,7 +364,7 @@ function ConvertTo-PortableVersion {
363
364
Add-Member - inputobject $customObject - Type ScriptMethod - Name IsContainedIn - Value {
364
365
param ( [object []]$collection )
365
366
foreach ( $object in $collection ) {
366
- if (
367
+ if (
367
368
$this.Major -eq $object.Major -and
368
369
$this.Minor -eq $object.Minor -and
369
370
$this.Patch -eq $object.Patch -and
@@ -422,10 +423,10 @@ function Get-InstalledCLIVersion {
422
423
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
423
424
# and use dotnet --version as a fallback
424
425
425
- $sdkList = dotnet -- list- sdks 2>&1
426
+ $sdkList = & $ script :dotnetExe -- list- sdks 2>&1
426
427
$sdkList = " Unknown option"
427
428
if ( $sdkList -match " Unknown option" ) {
428
- $installedVersions = dotnet -- version
429
+ $installedVersions = & $ script :dotnetExe -- version
429
430
}
430
431
else {
431
432
$installedVersions = $sdkList | Foreach-Object { $_.Split ()[0 ] }
@@ -475,3 +476,28 @@ function Receive-DotnetInstallScript
475
476
476
477
return $installScript.FullName
477
478
}
479
+
480
+ function Get-DotnetExe
481
+ {
482
+ $discoveredDotNet = Get-Command - CommandType Application dotnet
483
+ if ( $discoveredDotNet ) {
484
+ $discoveredDotNet | Select-Object - First 1 | Foreach-Object { $_.Source }
485
+ return
486
+ }
487
+ # it's not in the path, try harder to find it
488
+ # check the usual places
489
+ if ( ! (test-path variable:IsWindows) -or $IsWindows ) {
490
+ $dotnetHuntPath = " $HOME \AppData\Local\Microsoft\dotnet\dotnet.exe"
491
+ if ( test-path $dotnetHuntPath ) {
492
+ return $dotnetHuntPath
493
+ }
494
+ }
495
+ else {
496
+ $dotnetHuntPath = " $HOME /.dotnet/dotnet"
497
+ if ( test-path $dotnetHuntPath ) {
498
+ return $dotnetHuntPath
499
+ }
500
+ }
501
+ throw " Could not find dotnet executable"
502
+ }
503
+ $script :dotnetExe = Get-DotnetExe
0 commit comments