@@ -45,45 +45,62 @@ Param(
45
45
)
46
46
47
47
Write-Host " Preparing to run build script..."
48
+ $DotNetInstallerUri = ' https://dot.net/v1/dotnet-install.ps1' ;
49
+ $DotNetUnixInstallerUri = ' https://dot.net/v1/dotnet-install.sh'
50
+ $DotNetChannel = ' LTS'
51
+ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
48
52
49
- if ($PSEdition -eq " Desktop" ) { $IsWindows = $true }
50
-
51
- $CakeVersion = " 0.31.0"
52
-
53
- $DotNetChannel = " Current" ;
54
- $DotNetInstaller = if ($IsWindows ) { " dotnet-install.ps1" } else { " dotnet-install.sh" }
55
- $DotNetInstallerUri = " https://dot.net/v1/$DotNetInstaller " ;
56
- $DotNetVersion = (Get-Content ./ src/ global.json | ConvertFrom-Json ).sdk.version;
57
-
58
- $NugetUrl = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
53
+ [string ] $CakeVersion = ' '
54
+ [string ] $DotNetVersion = ' '
55
+ foreach ($line in Get-Content " $PSScriptRoot \build.config" )
56
+ {
57
+ if ($line -like ' CAKE_VERSION=*' ) {
58
+ $CakeVersion = $line.SubString (13 )
59
+ }
60
+ elseif ($line -like ' DOTNET_VERSION=*' ) {
61
+ $DotNetVersion = $line.SubString (15 )
62
+ }
63
+ }
59
64
60
- $PathSplitter = if ($IsWindows ) { ' ;' } else { ' :' }
61
65
62
- # SSL FIX
63
- [System.Net.ServicePointManager ]::SecurityProtocol = [System.Net.SecurityProtocolType ]::Tls12;
66
+ if ([string ]::IsNullOrEmpty($CakeVersion ) -or [string ]::IsNullOrEmpty($DotNetVersion )) {
67
+ ' Failed to parse Cake / .NET Core SDK Version'
68
+ exit 1
69
+ }
64
70
65
71
# Make sure tools folder exists
66
- $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
67
72
$ToolPath = Join-Path $PSScriptRoot " tools"
68
73
if (! (Test-Path $ToolPath )) {
69
74
Write-Verbose " Creating tools directory..."
70
- New-Item - Path $ToolPath - Type directory | out-null
75
+ New-Item - Path $ToolPath - Type Directory - Force | out-null
71
76
}
72
77
78
+ # SSL FIX
79
+ [System.Net.ServicePointManager ]::SecurityProtocol = [System.Net.SecurityProtocolType ]::Tls12;
80
+
73
81
# ##########################################################################
74
82
# INSTALL .NET CORE CLI
75
83
# ##########################################################################
76
- function Remove-PathVariable ([string ]$VariableToRemove ) {
84
+
85
+ Function Remove-PathVariable ([string ]$VariableToRemove )
86
+ {
87
+ $SplitChar = ' ;'
88
+ if ($IsMacOS -or $IsLinux ) {
89
+ $SplitChar = ' :'
90
+ }
91
+
77
92
$path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
78
- if ($path -ne $null ) {
79
- $newItems = $path.Split ($PathSplitter , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
80
- [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join($PathSplitter , $newItems ), " User" )
93
+ if ($path -ne $null )
94
+ {
95
+ $newItems = $path.Split ($SplitChar , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
96
+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join($SplitChar , $newItems ), " User" )
81
97
}
82
98
83
99
$path = [Environment ]::GetEnvironmentVariable(" PATH" , " Process" )
84
- if ($path -ne $null ) {
85
- $newItems = $path.Split ($PathSplitter , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
86
- [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join($PathSplitter , $newItems ), " Process" )
100
+ if ($path -ne $null )
101
+ {
102
+ $newItems = $path.Split ($SplitChar , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
103
+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join($SplitChar , $newItems ), " Process" )
87
104
}
88
105
}
89
106
@@ -95,55 +112,59 @@ if (Get-Command dotnet -ErrorAction SilentlyContinue) {
95
112
96
113
if ($FoundDotNetCliVersion -ne $DotNetVersion ) {
97
114
$InstallPath = Join-Path $PSScriptRoot " .dotnet"
98
-
99
115
if (! (Test-Path $InstallPath )) {
100
- New-Item - ItemType Directory $InstallPath | Out-Null ;
116
+ New-Item - Path $InstallPath - ItemType Directory - Force | Out-Null ;
101
117
}
102
118
103
- [string ] $InstalledDotNetVersion = Get-ChildItem - Path ./ .dotnet - File `
104
- | Where-Object { $_.Name -eq ' dotnet' -or $_.Name -eq ' dotnet.exe' } `
105
- | ForEach-Object { & $_.FullName -- version }
106
-
107
- if ($InstalledDotNetVersion -ne $DotNetVersion )
108
- {
109
- (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath /$DotNetInstaller " );
110
- $Cmd = " $InstallPath /$DotNetInstaller -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath -NoPath"
111
- if (! $IsWindows ) { $Cmd = " bash $Cmd " }
112
- Invoke-Expression " & $Cmd "
119
+ if ($IsMacOS -or $IsLinux ) {
120
+ (New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri , " $InstallPath \dotnet-install.sh" );
121
+ & bash $InstallPath \dotnet- install.sh -- version " $DotNetVersion " -- install-dir " $InstallPath " -- channel " $DotNetChannel " -- no- path
122
+ }
123
+ else {
124
+ (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath \dotnet-install.ps1" );
125
+ & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
113
126
}
114
127
115
- # Ensure the installed .NET Core CLI is always used but putting it on the front of the path.
116
128
Remove-PathVariable " $InstallPath "
117
- $env: PATH = " $InstallPath$PathSplitter$env: PATH "
118
- $env: DOTNET_ROOT = " $InstallPath "
129
+ $env: PATH = " $InstallPath ;$env: PATH "
119
130
}
120
131
121
- # Temporarily skip verification of addins.
122
- $env: CAKE_SETTINGS_SKIPVERIFICATION = ' true'
123
132
$env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
124
133
$env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
125
134
126
- # ##########################################################################
127
- # INSTALL NUGET
128
- # ##########################################################################
129
-
130
- # Make sure nuget.exe exists.
131
- $NugetPath = Join-Path $ToolPath " nuget.exe"
132
- if (! (Test-Path $NugetPath )) {
133
- Write-Host " Downloading NuGet.exe..."
134
- (New-Object System.Net.WebClient).DownloadFile($NugetUrl , $NugetPath );
135
- }
136
135
137
136
# ##########################################################################
138
137
# INSTALL CAKE
139
138
# ##########################################################################
140
139
141
140
# Make sure Cake has been installed.
142
- Write-Host " Installing Cake..."
143
- $CakeInstallPath = Join-Path $PSScriptRoot " .cake"
144
- if (! (Test-Path $CakeInstallPath )) {
145
- New-Item - ItemType Directory $CakeInstallPath | Out-Null ;
146
- Invoke-Expression " & dotnet tool install Cake.Tool --version $CakeVersion --tool-path $CakeInstallPath "
141
+ [string ] $CakeExePath = ' '
142
+ [string ] $CakeInstalledVersion = Get-Command dotnet- cake - ErrorAction SilentlyContinue | % {& $_.Source -- version}
143
+
144
+ if ($CakeInstalledVersion -eq $CakeVersion ) {
145
+ # Cake found locally
146
+ $CakeExePath = (Get-Command dotnet- cake).Source
147
+ }
148
+ else {
149
+ $CakePath = Join-Path $ToolPath " .store\cake.tool\$CakeVersion "
150
+ $CakeExePath = (Get-ChildItem - Path $ToolPath - Filter " dotnet-cake*" - File| ForEach-Object FullName | Select-Object - First 1 )
151
+
152
+
153
+ if ((! (Test-Path - Path $CakePath - PathType Container)) -or (! (Test-Path $CakeExePath - PathType Leaf))) {
154
+
155
+ if ((! [string ]::IsNullOrEmpty($CakeExePath )) -and (Test-Path $CakeExePath - PathType Leaf))
156
+ {
157
+ & dotnet tool uninstall -- tool- path $ToolPath Cake.Tool
158
+ }
159
+
160
+ & dotnet tool install -- tool- path $ToolPath -- version $CakeVersion Cake.Tool
161
+ if ($LASTEXITCODE -ne 0 )
162
+ {
163
+ ' Failed to install cake'
164
+ exit 1
165
+ }
166
+ $CakeExePath = (Get-ChildItem - Path $ToolPath - Filter " dotnet-cake*" - File| ForEach-Object FullName | Select-Object - First 1 )
167
+ }
147
168
}
148
169
149
170
# ###########################################################################
@@ -162,8 +183,11 @@ $Arguments = @{
162
183
# Start Cake
163
184
Write-Host " Running build script..."
164
185
165
- $Cmd = " $CakeInstallPath /dotnet-cake $Script $Arguments "
166
- Invoke-Expression " & $Cmd "
186
+ & " $CakeExePath " $Script -- bootstrap
187
+ if ($LASTEXITCODE -eq 0 )
188
+ {
189
+ & " $CakeExePath " $Script $Arguments
190
+ }
167
191
168
192
if ($env: APPVEYOR ) {
169
193
$host.SetShouldExit ($LASTEXITCODE )
0 commit comments