From 8de0ddc6d16474ec895bf3559fd15683656589fc Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 30 Apr 2020 11:28:32 -0700 Subject: [PATCH] Add ability to `Install-Dotnet` to specify directory (#12469) --- build.psm1 | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/build.psm1 b/build.psm1 index 654f3346e..0550342c7 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1628,7 +1628,8 @@ function Install-Dotnet { param( [string]$Channel = $dotnetCLIChannel, [string]$Version = $dotnetCLIRequiredVersion, - [switch]$NoSudo + [switch]$NoSudo, + [string]$InstallDir ) # This allows sudo install to be optional; needed when running in containers / as root @@ -1662,7 +1663,12 @@ function Install-Dotnet { $installScript = "dotnet-install.sh" Start-NativeExecution { & $curl -sO $installObtainUrl/$installScript - bash ./$installScript -c $Channel -v $Version + + if (-not $InstallDir) { + bash ./$installScript -c $Channel -v $Version + } else { + bash ./$installScript -c $Channel -v $Version -i $InstallDir + } } } elseif ($environment.IsWindows) { Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet @@ -1670,12 +1676,22 @@ function Install-Dotnet { Invoke-WebRequest -Uri $installObtainUrl/$installScript -OutFile $installScript if (-not $environment.IsCoreCLR) { - & ./$installScript -Channel $Channel -Version $Version + if (-not $InstallDir) { + & ./$installScript -Channel $Channel -Version $Version + } else { + & ./$installScript -Channel $Channel -Version $Version -InstallDir $InstallDir + } } else { # dotnet-install.ps1 uses APIs that are not supported in .NET Core, so we run it with Windows PowerShell $fullPSPath = Join-Path -Path $env:windir -ChildPath "System32\WindowsPowerShell\v1.0\powershell.exe" $fullDotnetInstallPath = Join-Path -Path $PWD.Path -ChildPath $installScript - Start-NativeExecution { & $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version } + Start-NativeExecution { + if (-not $InstallDir) { + & $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version + } else { + & $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version -InstallDir $InstallDir + } + } } } }