@@ -25,10 +25,6 @@ Specifies the amount of information to be displayed.
25
25
Shows description about tasks.
26
26
. PARAMETER DryRun
27
27
Performs a dry run.
28
- . PARAMETER Experimental
29
- Uses the nightly builds of the Roslyn script engine.
30
- . PARAMETER Mono
31
- Uses the Mono Compiler rather than the Roslyn script engine.
32
28
. PARAMETER SkipToolPackageRestore
33
29
Skips restoring of packages.
34
30
. PARAMETER ScriptArgs
@@ -49,13 +45,28 @@ Param(
49
45
[switch ]$ShowDescription ,
50
46
[Alias (" WhatIf" , " Noop" )]
51
47
[switch ]$DryRun ,
52
- [switch ]$Experimental ,
53
- [switch ]$Mono ,
54
48
[switch ]$SkipToolPackageRestore ,
55
49
[Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
56
50
[string []]$ScriptArgs
57
51
)
58
52
53
+ # Attempt to set highest encryption available for SecurityProtocol.
54
+ # PowerShell will not set this by default (until maybe .NET 4.6.x). This
55
+ # will typically produce a message for PowerShell v2 (just an info
56
+ # message though)
57
+ try {
58
+ # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
59
+ # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
60
+ # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
61
+ # installed (.NET 4.5 is an in-place upgrade).
62
+ # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that.
63
+ if (-not $IsCoreCLR ) {
64
+ [System.Net.ServicePointManager ]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
65
+ }
66
+ } catch {
67
+ Write-Output ' Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3'
68
+ }
69
+
59
70
[Reflection.Assembly ]::LoadWithPartialName(" System.Security" ) | Out-Null
60
71
function MD5HashFile ([string ] $filePath )
61
72
{
@@ -85,7 +96,7 @@ function GetProxyEnabledWebClient
85
96
{
86
97
$wc = New-Object System.Net.WebClient
87
98
$proxy = [System.Net.WebRequest ]::GetSystemWebProxy()
88
- $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
99
+ $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
89
100
$wc.Proxy = $proxy
90
101
return $wc
91
102
}
@@ -110,15 +121,16 @@ $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
110
121
# Make sure tools folder exists
111
122
if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
112
123
Write-Verbose - Message " Creating tools directory..."
113
- New-Item - Path $TOOLS_DIR - Type directory | out-null
124
+ New-Item - Path $TOOLS_DIR - Type Directory | Out-Null
114
125
}
115
126
116
127
# Make sure that packages.config exist.
117
128
if (! (Test-Path $PACKAGES_CONFIG )) {
118
- Write-Verbose - Message " Downloading packages.config..."
119
- try {
129
+ Write-Verbose - Message " Downloading packages.config..."
130
+ try {
120
131
$wc = GetProxyEnabledWebClient
121
- $wc.DownloadFile (" https://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG ) } catch {
132
+ $wc.DownloadFile (" https://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG )
133
+ } catch {
122
134
Throw " Could not download packages.config."
123
135
}
124
136
}
@@ -146,24 +158,30 @@ if (!(Test-Path $NUGET_EXE)) {
146
158
}
147
159
148
160
# Save nuget.exe path to environment to be available to child processed
149
- $ENV: NUGET_EXE = $NUGET_EXE
161
+ $env: NUGET_EXE = $NUGET_EXE
162
+ $env: NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS ) {
163
+ " mono `" $NUGET_EXE `" "
164
+ } else {
165
+ " `" $NUGET_EXE `" "
166
+ }
150
167
151
168
# Restore tools from NuGet?
152
169
if (-Not $SkipToolPackageRestore.IsPresent ) {
153
170
Push-Location
154
171
Set-Location $TOOLS_DIR
155
172
156
173
# Check for changes in packages.config and remove installed tools if true.
157
- [string ] $md5Hash = MD5HashFile( $PACKAGES_CONFIG )
174
+ [string ] $md5Hash = MD5HashFile $PACKAGES_CONFIG
158
175
if ((! (Test-Path $PACKAGES_CONFIG_MD5 )) -Or
159
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
176
+ ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
160
177
Write-Verbose - Message " Missing or changed package.config hash..."
161
178
Get-ChildItem - Exclude packages.config, nuget.exe , Cake.Bakery |
162
- Remove-Item - Recurse
179
+ Remove-Item - Recurse - Force
163
180
}
164
181
165
182
Write-Verbose - Message " Restoring tools from NuGet..."
166
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
183
+
184
+ $NuGetOutput = Invoke-Expression " & $env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
167
185
168
186
if ($LASTEXITCODE -ne 0 ) {
169
187
Throw " An error occurred while restoring NuGet tools."
@@ -172,7 +190,7 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
172
190
{
173
191
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
174
192
}
175
- Write-Verbose - Message ($NuGetOutput | out-string )
193
+ Write-Verbose - Message ($NuGetOutput | Out-String )
176
194
177
195
Pop-Location
178
196
}
@@ -183,13 +201,13 @@ if (Test-Path $ADDINS_PACKAGES_CONFIG) {
183
201
Set-Location $ADDINS_DIR
184
202
185
203
Write-Verbose - Message " Restoring addins from NuGet..."
186
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
204
+ $NuGetOutput = Invoke-Expression " & $ env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
187
205
188
206
if ($LASTEXITCODE -ne 0 ) {
189
207
Throw " An error occurred while restoring NuGet addins."
190
208
}
191
209
192
- Write-Verbose - Message ($NuGetOutput | out-string )
210
+ Write-Verbose - Message ($NuGetOutput | Out-String )
193
211
194
212
Pop-Location
195
213
}
@@ -200,13 +218,13 @@ if (Test-Path $MODULES_PACKAGES_CONFIG) {
200
218
Set-Location $MODULES_DIR
201
219
202
220
Write-Verbose - Message " Restoring modules from NuGet..."
203
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
221
+ $NuGetOutput = Invoke-Expression " & $ env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
204
222
205
223
if ($LASTEXITCODE -ne 0 ) {
206
224
Throw " An error occurred while restoring NuGet modules."
207
225
}
208
226
209
- Write-Verbose - Message ($NuGetOutput | out-string )
227
+ Write-Verbose - Message ($NuGetOutput | Out-String )
210
228
211
229
Pop-Location
212
230
}
@@ -216,20 +234,23 @@ if (!(Test-Path $CAKE_EXE)) {
216
234
Throw " Could not find Cake.exe at $CAKE_EXE "
217
235
}
218
236
237
+ $CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS ) {
238
+ " mono `" $CAKE_EXE `" "
239
+ } else {
240
+ " `" $CAKE_EXE `" "
241
+ }
219
242
220
-
221
- # Build Cake arguments
222
- $ cakeArguments = @ ( " $Script " );
223
- if ($Target ) { $cakeArguments += " -target=$Target " }
243
+ # Build an array (not a string) of Cake arguments to be joined later
244
+ $cakeArguments = @ ()
245
+ if ( $Script ) { $ cakeArguments += " `" $Script `" " }
246
+ if ($Target ) { $cakeArguments += " -target=`" $Target `" " }
224
247
if ($Configuration ) { $cakeArguments += " -configuration=$Configuration " }
225
248
if ($Verbosity ) { $cakeArguments += " -verbosity=$Verbosity " }
226
249
if ($ShowDescription ) { $cakeArguments += " -showdescription" }
227
250
if ($DryRun ) { $cakeArguments += " -dryrun" }
228
- if ($Experimental ) { $cakeArguments += " -experimental" }
229
- if ($Mono ) { $cakeArguments += " -mono" }
230
251
$cakeArguments += $ScriptArgs
231
252
232
253
# Start Cake
233
254
Write-Host " Running build script..."
234
- & $CAKE_EXE $ cakeArguments
255
+ Invoke-Expression " & $CAKE_EXE_INVOCATION $ ( $ cakeArguments -join " " ) "
235
256
exit $LASTEXITCODE
0 commit comments