Skip to content

Commit

Permalink
Improve logic for handling a system where dotnet has never been insta…
Browse files Browse the repository at this point in the history
…lled
  • Loading branch information
JamesWTruher committed Feb 14, 2019
1 parent 020c086 commit fcf73b6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ function Start-ScriptAnalyzerBuild

BEGIN {
# don't allow the build to be started unless we have the proper Cli version
# this will not actually install dotnet if it's already present, but it will
# install the proper version
Install-Dotnet
if ( -not (Test-SuitableDotnet) ) {
$requiredVersion = Get-GlobalJsonSdkVersion
$foundVersion = Get-InstalledCLIVersion
Expand Down Expand Up @@ -202,6 +205,9 @@ function Start-ScriptAnalyzerBuild
try {
Push-Location $projectRoot/Rules
Write-Progress "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
if ( -not $script:DotnetExe ) {
$script:dotnetExe = Get-DotnetExe
}
$buildOutput = & $script:dotnetExe build --framework $framework --configuration "$config"
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
}
Expand Down Expand Up @@ -308,6 +314,11 @@ function Install-Dotnet
If ( $PSCmdlet.ShouldProcess("$installScriptName for $version")) {
& "${installScriptPath}" -c release -version $version
}
# this may be the first time that dotnet has been installed,
# set up the executable variable
if ( -not $script:DotnetExe ) {
$script:DotnetExe = Get-DotnetExe
}
}
catch {
throw $_
Expand Down Expand Up @@ -336,7 +347,10 @@ function ConvertTo-PortableVersion {
foreach ( $v in $strVersion ) {
$ver, $pre = $v.split("-",2)
try {
[int]$major, [int]$minor, [int]$patch = $ver.Split(".")
[int]$major, [int]$minor, [int]$patch, $unused = $ver.Split(".",4)
if ( -not $pre ) {
$pre = $unused
}
}
catch {
Write-Warning "Cannot convert '$v' to portable version"
Expand Down Expand Up @@ -420,6 +434,10 @@ function Test-SuitableDotnet {

# these are mockable functions for testing
function Get-InstalledCLIVersion {
# dotnet might not have been installed _ever_, so just return 0.0.0.0
if ( -not $script:DotnetExe ) {
return (ConvertTo-PortableVersion 0.0.0)
}
try {
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
# and use dotnet --version as a fallback
Expand Down

0 comments on commit fcf73b6

Please sign in to comment.