@@ -128,6 +128,9 @@ function Start-ScriptAnalyzerBuild
128
128
129
129
BEGIN {
130
130
# don't allow the build to be started unless we have the proper Cli version
131
+ # this will not actually install dotnet if it's already present, but it will
132
+ # install the proper version
133
+ Install-Dotnet
131
134
if ( -not (Test-SuitableDotnet ) ) {
132
135
$requiredVersion = Get-GlobalJsonSdkVersion
133
136
$foundVersion = Get-InstalledCLIVersion
@@ -202,6 +205,9 @@ function Start-ScriptAnalyzerBuild
202
205
try {
203
206
Push-Location $projectRoot / Rules
204
207
Write-Progress " Building ScriptAnalyzer for PSVersion '$PSVersion ' using framework '$framework ' and configuration '$Configuration '"
208
+ if ( -not $script :DotnetExe ) {
209
+ $script :dotnetExe = Get-DotnetExe
210
+ }
205
211
$buildOutput = & $script :dotnetExe build -- framework $framework -- configuration " $config "
206
212
if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
207
213
}
@@ -308,6 +314,11 @@ function Install-Dotnet
308
314
If ( $PSCmdlet.ShouldProcess (" $installScriptName for $version " )) {
309
315
& " ${installScriptPath} " - c release - version $version
310
316
}
317
+ # this may be the first time that dotnet has been installed,
318
+ # set up the executable variable
319
+ if ( -not $script :DotnetExe ) {
320
+ $script :DotnetExe = Get-DotnetExe
321
+ }
311
322
}
312
323
catch {
313
324
throw $_
@@ -336,7 +347,10 @@ function ConvertTo-PortableVersion {
336
347
foreach ( $v in $strVersion ) {
337
348
$ver , $pre = $v.split (" -" , 2 )
338
349
try {
339
- [int ]$major , [int ]$minor , [int ]$patch = $ver.Split (" ." )
350
+ [int ]$major , [int ]$minor , [int ]$patch , $unused = $ver.Split (" ." , 4 )
351
+ if ( -not $pre ) {
352
+ $pre = $unused
353
+ }
340
354
}
341
355
catch {
342
356
Write-Warning " Cannot convert '$v ' to portable version"
@@ -420,6 +434,10 @@ function Test-SuitableDotnet {
420
434
421
435
# these are mockable functions for testing
422
436
function Get-InstalledCLIVersion {
437
+ # dotnet might not have been installed _ever_, so just return 0.0.0.0
438
+ if ( -not $script :DotnetExe ) {
439
+ return (ConvertTo-PortableVersion 0.0 .0 )
440
+ }
423
441
try {
424
442
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
425
443
# and use dotnet --version as a fallback
0 commit comments