1- $CakeVersion = " 0.24 .0"
1+ $CakeVersion = " 0.25 .0"
22$DotNetChannel = " LTS" ;
3- $DotNetVersion = " 2.1.3" ;
4- $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/v2.1.3/scripts/obtain/dotnet-install.ps1" ;
5- $ENV: CAKE_NUGET_USEINPROCESSCLIENT = ' true'
3+ $DotNetVersion = " 2.1.4" ;
4+ $IsRunningOnUnix = [System.Environment ]::OSVersion.Platform -eq [System.PlatformID ]::Unix
65
76# Make sure tools folder exists
87$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
@@ -34,23 +33,44 @@ Function Remove-PathVariable([string]$VariableToRemove)
3433}
3534
3635# Get .NET Core CLI path if installed.
37- $FoundDotNetCliVersion = $null ;
36+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
37+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
38+ $FoundDotNetCliVersion = $null
39+
40+
3841if (Get-Command dotnet - ErrorAction SilentlyContinue) {
39- $FoundDotNetCliVersion = dotnet -- version;
42+ $FoundDotNetCliVersion = dotnet -- version
4043}
4144
42- if ($FoundDotNetCliVersion -ne $DotNetVersion ) {
45+ if ($FoundDotNetCliVersion -ne $DotNetVersion )
46+ {
4347 $InstallPath = Join-Path $PSScriptRoot " .dotnet"
48+ Remove-PathVariable " $InstallPath "
49+ $env: PATH = " $InstallPath ;$env: PATH "
50+
4451 if (! (Test-Path $InstallPath )) {
45- mkdir - Force $InstallPath | Out-Null ;
52+ New-Item - ItemType Directory - Force $InstallPath | Out-Null ;
4653 }
47- (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath \dotnet-install.ps1" );
48- & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
4954
50- Remove-PathVariable " $InstallPath "
51- $env: PATH = " $InstallPath ;$env: PATH "
52- $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
53- $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
55+ [string ] $InstalledDotNetVersion = Get-ChildItem - Path ./ .dotnet - File `
56+ | Where-Object { $_.Name -eq ' dotnet' -or $_.Name -eq ' dotnet.exe' } `
57+ | ForEach-Object { & $_.FullName -- version }
58+
59+ if ($InstalledDotNetVersion -eq $DotNetVersion )
60+ {
61+ }
62+ elseif ($IsRunningOnUnix )
63+ {
64+ $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.sh" ;
65+ (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath /dotnet-install.sh" );
66+ sudo bash " $InstallPath /dotnet-install.sh" -- version $DotNetVersion -- install-dir " $InstallPath " -- no- path
67+ }
68+ else
69+ {
70+ $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.ps1" ;
71+ (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath \dotnet-install.ps1" );
72+ & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
73+ }
5474}
5575
5676# ##########################################################################
@@ -67,17 +87,34 @@ Function Unzip
6787
6888
6989# Make sure Cake has been installed.
70- $CakePath = Join-Path $ToolPath " Cake.$CakeVersion /Cake.exe"
71- if (! (Test-Path $CakePath )) {
90+ $CakePath = Join-Path $ToolPath " Cake.$CakeVersion "
91+ $CakeExePath = Join-Path $CakePath " Cake.exe"
92+ $CakeZipPath = Join-Path $ToolPath " Cake.zip"
93+ if (! (Test-Path $CakeExePath )) {
7294 Write-Host " Installing Cake $CakeVersion ..."
73- (New-Object System.Net.WebClient).DownloadFile(" https://www.nuget.org/api/v2/package/Cake/$CakeVersion " , " $ToolPath \Cake.zip " )
74- Unzip " $ToolPath \Cake.zip " " $ToolPath /Cake. $CakeVersion "
75- Remove-Item " $ToolPath \Cake.zip "
95+ (New-Object System.Net.WebClient).DownloadFile(" https://www.nuget.org/api/v2/package/Cake/$CakeVersion " , $CakeZipPath )
96+ Unzip $CakeZipPath $CakePath
97+ Remove-Item $CakeZipPath
7698}
7799
78100# ##########################################################################
79101# RUN BUILD SCRIPT
80102# ##########################################################################
81-
82- & " $CakePath " $args
83- exit $LASTEXITCODE
103+ if ($IsRunningOnUnix )
104+ {
105+ & mono " $CakeExePath " -- bootstrap
106+ if ($LASTEXITCODE -eq 0 )
107+ {
108+ & mono " $CakeExePath " $args
109+ }
110+ exit $LASTEXITCODE
111+ }
112+ else
113+ {
114+ & " $CakeExePath " -- bootstrap
115+ if ($LASTEXITCODE -eq 0 )
116+ {
117+ & " $CakeExePath " $args
118+ }
119+ exit $LASTEXITCODE
120+ }
0 commit comments