Skip to content

Commit 2df5451

Browse files
committed
Update appveyor.psm1 to use build script bootstrapping for installing dotnet CLI
update build script to handle WMF4 better (theoretically)
1 parent ecc4b3f commit 2df5451

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

build.psm1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,17 @@ function Test-SuitableDotnet {
419419
# these are mockable functions for testing
420420
function Get-InstalledCLIVersion {
421421
try {
422-
$installedVersions = dotnet --list-sdks | Foreach-Object { $_.Split()[0] }
422+
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
423+
# and use dotnet --version as a fallback
424+
425+
$sdkList = dotnet --list-sdks 2>&1
426+
$sdkList = "Unknown option"
427+
if ( $sdkList -match "Unknown option" ) {
428+
$installedVersions = dotnet --version
429+
}
430+
else {
431+
$installedVersions = $sdkList | Foreach-Object { $_.Split()[0] }
432+
}
423433
}
424434
catch {
425435
$installedVersions = @()

tools/appveyor.psm1

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,10 @@ function Invoke-AppVeyorInstall {
3131
Install-Module -Name platyPS -Force -Scope CurrentUser -RequiredVersion $platyPSVersion
3232
}
3333

34-
# the legacy WMF4 image only has the old preview SDKs of dotnet
35-
$globalDotJson = Get-Content (Join-Path $PSScriptRoot '..\global.json') -Raw | ConvertFrom-Json
36-
$requiredDotNetCoreSDKVersion = $globalDotJson.sdk.version
37-
if ($PSVersionTable.PSVersion.Major -gt 4) {
38-
$requiredDotNetCoreSDKVersionPresent = (dotnet --list-sdks) -match $requiredDotNetCoreSDKVersion
39-
}
40-
else {
41-
# WMF 4 image has old SDK that does not have --list-sdks parameter
42-
$requiredDotNetCoreSDKVersionPresent = (dotnet --version).StartsWith($requiredDotNetCoreSDKVersion)
43-
}
44-
if (-not $requiredDotNetCoreSDKVersionPresent) {
45-
Write-Verbose -Verbose "Installing required .Net CORE SDK $requiredDotNetCoreSDKVersion"
46-
$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
47-
try {
48-
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
49-
if ($IsLinux -or $isMacOS) {
50-
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.sh' -OutFile dotnet-install.sh
51-
bash dotnet-install.sh --version $requiredDotNetCoreSDKVersion
52-
[System.Environment]::SetEnvironmentVariable('PATH', "/home/appveyor/.dotnet$([System.IO.Path]::PathSeparator)$PATH")
53-
}
54-
else {
55-
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
56-
.\dotnet-install.ps1 -Version $requiredDotNetCoreSDKVersion
57-
}
58-
}
59-
finally {
60-
[Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol
61-
Remove-Item .\dotnet-install.*
62-
}
63-
}
34+
Write-Verbose -Verbose "Installing required .Net CORE SDK $requiredDotNetCoreSDKVersion"
35+
# the build script sorts out the problems of WMF4 and earlier versions of dotnet CLI
36+
$buildScriptDir = (Resolve-Path "$PSScriptRoot/..").Path
37+
& "$buildScriptDir/build.ps1" -bootstrap
6438
}
6539

6640
# Implements AppVeyor 'test_script' step

0 commit comments

Comments
 (0)