From 91f160f479cee906efd6f248b9269fd23c625cd9 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 29 Apr 2020 15:34:13 -0700 Subject: [PATCH 1/2] Add the .NET SDK installation path to the current process path --- tools/UpdateDotnetRuntime.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 550330471b1..95063c863cc 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -13,6 +13,11 @@ param ( function Update-GlobalJson([string] $Version) { $psGlobalJsonPath = Resolve-Path "$PSScriptRoot/../global.json" $psGlobalJson = Get-Content -Path $psGlobalJsonPath -Raw | ConvertFrom-Json + + if ($psGlobalJson.sdk.version -eq $Version) { + throw '.NET SDK version is not updated' + } + $psGlobalJson.sdk.version = $Version $psGlobalJson | ConvertTo-Json | Out-File -FilePath $psGlobalJsonPath -Force } @@ -147,6 +152,16 @@ Install-Dotnet -Channel "$Channel" -Version $sdkVersion Write-Verbose -Message "Installing .NET SDK completed." -Verbose +$isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT + +$dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" } + +$pathSep = [System.IO.Path]::PathSeparator + +if (-not (($ENV:PATH -split $pathSep) -contains "$dotnetPath")) { + $env:PATH = "$dotnetPath" + $pathSep + "$ENV:PATH" +} + $latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1 Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose From 03536dda0c4bd77d88f430eda62630beba5bac4e Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 29 Apr 2020 16:49:39 -0700 Subject: [PATCH 2/2] Add trim before writing file to avoid extra line at the bottom --- tools/UpdateDotnetRuntime.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 95063c863cc..b49d1c47e43 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -123,7 +123,7 @@ function Update-CsprojFile([string] $path, $values) { } if ($updated) { - $fileContent | Out-File -FilePath $path -Force + ($fileContent).TrimEnd() | Out-File -FilePath $path -Force } }