Skip to content

Commit fcf73b6

Browse files
committed
Improve logic for handling a system where dotnet has never been installed
1 parent 020c086 commit fcf73b6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

build.psm1

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ function Start-ScriptAnalyzerBuild
128128

129129
BEGIN {
130130
# 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
131134
if ( -not (Test-SuitableDotnet) ) {
132135
$requiredVersion = Get-GlobalJsonSdkVersion
133136
$foundVersion = Get-InstalledCLIVersion
@@ -202,6 +205,9 @@ function Start-ScriptAnalyzerBuild
202205
try {
203206
Push-Location $projectRoot/Rules
204207
Write-Progress "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
208+
if ( -not $script:DotnetExe ) {
209+
$script:dotnetExe = Get-DotnetExe
210+
}
205211
$buildOutput = & $script:dotnetExe build --framework $framework --configuration "$config"
206212
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
207213
}
@@ -308,6 +314,11 @@ function Install-Dotnet
308314
If ( $PSCmdlet.ShouldProcess("$installScriptName for $version")) {
309315
& "${installScriptPath}" -c release -version $version
310316
}
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+
}
311322
}
312323
catch {
313324
throw $_
@@ -336,7 +347,10 @@ function ConvertTo-PortableVersion {
336347
foreach ( $v in $strVersion ) {
337348
$ver, $pre = $v.split("-",2)
338349
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+
}
340354
}
341355
catch {
342356
Write-Warning "Cannot convert '$v' to portable version"
@@ -420,6 +434,10 @@ function Test-SuitableDotnet {
420434

421435
# these are mockable functions for testing
422436
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+
}
423441
try {
424442
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
425443
# and use dotnet --version as a fallback

0 commit comments

Comments
 (0)