Skip to content

Commit 350309a

Browse files
committed
(build) use the dotnet installed on the host if possible
1 parent d20e418 commit 350309a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

build.ps1

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,40 @@ Function Add-PathVariable([string]$PathToAdd)
117117

118118
Function Install-Dotnet($DotNetVersion)
119119
{
120-
if ($IsMacOS -or $IsLinux) {
121-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
122-
if (!(Test-Path $ScriptPath)) {
123-
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
120+
if (!(Check-DotnetInstalled $DotNetVersion))
121+
{
122+
if ($IsMacOS -or $IsLinux) {
123+
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
124+
if (!(Test-Path $ScriptPath)) {
125+
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
126+
}
127+
128+
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
124129
}
130+
else {
131+
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
132+
if (!(Test-Path $ScriptPath)) {
133+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
134+
}
125135

126-
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
127-
}
128-
else {
129-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
130-
if (!(Test-Path $ScriptPath)) {
131-
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
136+
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
132137
}
138+
}
139+
}
133140

134-
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
141+
Function Check-DotnetInstalled($version)
142+
{
143+
if (Get-Command dotnet -errorAction SilentlyContinue)
144+
{
145+
$sdk = dotnet --list-sdks
146+
$result = $sdk | ? { $v = $_.Split(" ")[0]; $v -eq $version }
147+
if ($result -ne $null)
148+
{
149+
Write-Host "The dotnet version $version was installed globally, not installing";
150+
return $true;
151+
}
135152
}
153+
return $false;
136154
}
137155

138156
# Get .NET Core CLI path if installed.

0 commit comments

Comments
 (0)