@@ -202,6 +202,9 @@ function Start-ScriptAnalyzerBuild
202202 try {
203203 Push-Location $projectRoot / Rules
204204 Write-Progress " Building ScriptAnalyzer for PSVersion '$PSVersion ' using framework '$framework ' and configuration '$Configuration '"
205+ if ( -not $script :DotnetExe ) {
206+ $script :dotnetExe = Get-DotnetExe
207+ }
205208 $buildOutput = & $script :dotnetExe build -- framework $framework -- configuration " $config "
206209 if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
207210 }
@@ -308,6 +311,11 @@ function Install-Dotnet
308311 If ( $PSCmdlet.ShouldProcess (" $installScriptName for $version " )) {
309312 & " ${installScriptPath} " - c release - version $version
310313 }
314+ # this may be the first time that dotnet has been installed,
315+ # set up the executable variable
316+ if ( -not $script :DotnetExe ) {
317+ $script :DotnetExe = Get-DotnetExe
318+ }
311319 }
312320 catch {
313321 throw $_
@@ -336,7 +344,10 @@ function ConvertTo-PortableVersion {
336344 foreach ( $v in $strVersion ) {
337345 $ver , $pre = $v.split (" -" , 2 )
338346 try {
339- [int ]$major , [int ]$minor , [int ]$patch = $ver.Split (" ." )
347+ [int ]$major , [int ]$minor , [int ]$patch , $unused = $ver.Split (" ." , 4 )
348+ if ( -not $pre ) {
349+ $pre = $unused
350+ }
340351 }
341352 catch {
342353 Write-Warning " Cannot convert '$v ' to portable version"
@@ -420,6 +431,10 @@ function Test-SuitableDotnet {
420431
421432# these are mockable functions for testing
422433function Get-InstalledCLIVersion {
434+ # dotnet might not have been installed _ever_, so just return 0.0.0.0
435+ if ( -not $script :DotnetExe ) {
436+ return (ConvertTo-PortableVersion 0.0 .0 )
437+ }
423438 try {
424439 # earlier versions of dotnet do not support --list-sdks, so we'll check the output
425440 # and use dotnet --version as a fallback
0 commit comments