Skip to content

Commit fdb2095

Browse files
authored
Fix .NET installation (#1320)
1 parent 67987fc commit fdb2095

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

PowerShellEditorServices.build.ps1

+35-13
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,52 @@ function Invoke-WithCreateDefaultHook {
5555

5656
function Install-Dotnet {
5757
param (
58-
$Channel
58+
[string[]]$Channel
5959
)
6060

61-
Write-Host "`n### Installing .NET CLI $Version...`n" -ForegroundColor Green
61+
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
62+
63+
Write-Host "Installing .NET channels $Channel" -ForegroundColor Green
6264

6365
# The install script is platform-specific
6466
$installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" }
67+
$installScript = "dotnet-install.$installScriptExt"
6568

6669
# Download the official installation script and run it
67-
$installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt"
68-
Invoke-WebRequest "https://dot.net/v1/dotnet-install.$installScriptExt" -OutFile $installScriptPath
69-
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
70+
$installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript
71+
Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath
72+
73+
# Download and install the different .NET channels
74+
foreach ($dotnetChannel in $Channel)
75+
{
76+
Write-Host "`n### Installing .NET CLI $Version...`n"
77+
78+
if ($script:IsUnix) {
79+
chmod +x $installScriptPath
80+
}
81+
82+
$params = if ($script:IsUnix)
83+
{
84+
@('-Channel', $dotnetChannel, '-InstallDir', $env:DOTNET_INSTALL_DIR, '-NoPath', '-Verbose')
85+
}
86+
else
87+
{
88+
@{
89+
Channel = $dotnetChannel
90+
InstallDir = $env:DOTNET_INSTALL_DIR
91+
NoPath = $true
92+
Verbose = $true
93+
}
94+
}
95+
96+
& $installScriptPath @params
7097

71-
if ($script:IsUnix) {
72-
chmod +x $installScriptPath
98+
Write-Host "`n### Installation complete for version $Version."
7399
}
74100

75-
$paramArr = @('-Channel', $Channel, '-InstallDir', "'$env:DOTNET_INSTALL_DIR'", '-NoPath')
76-
Invoke-Expression "$installScriptPath $paramArr"
77101
$env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH
78102

79-
Write-Host "`n### Installation complete." -ForegroundColor Green
103+
Write-Host '.NET installation complete' -ForegroundColor Green
80104
}
81105

82106
task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E {
@@ -85,9 +109,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7,
85109
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
86110

87111
if (!(Test-Path $dotnetExePath)) {
88-
Install-Dotnet -Channel '2.1'
89-
Install-Dotnet -Channel '3.1'
90-
Install-Dotnet -Channel 'release/5.0.1xx-preview6'
112+
Install-Dotnet -Channel '2.1','3.1','release/5.0.1xx-preview6'
91113
}
92114

93115
# This variable is used internally by 'dotnet' to know where it's installed

0 commit comments

Comments
 (0)