@@ -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
@@ -41,21 +37,41 @@ https://cakebuild.net
41
37
42
38
[CmdletBinding ()]
43
39
Param (
44
- [string ]$Script = " build.cake " ,
40
+ [string ]$Script ,
45
41
[string ]$Target ,
46
42
[string ]$Configuration ,
47
43
[ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
48
44
[string ]$Verbosity ,
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
+ # This is an automatic variable in PowerShell Core, but not in Windows PowerShell 5.x
54
+ if (-not (Test-Path variable:global:IsCoreCLR)) {
55
+ $IsCoreCLR = $false
56
+ }
57
+
58
+ # Attempt to set highest encryption available for SecurityProtocol.
59
+ # PowerShell will not set this by default (until maybe .NET 4.6.x). This
60
+ # will typically produce a message for PowerShell v2 (just an info
61
+ # message though)
62
+ try {
63
+ # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
64
+ # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
65
+ # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
66
+ # installed (.NET 4.5 is an in-place upgrade).
67
+ # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that.
68
+ if (-not $IsCoreCLR ) {
69
+ [System.Net.ServicePointManager ]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
70
+ }
71
+ } catch {
72
+ 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'
73
+ }
74
+
59
75
[Reflection.Assembly ]::LoadWithPartialName(" System.Security" ) | Out-Null
60
76
function MD5HashFile ([string ] $filePath )
61
77
{
@@ -85,7 +101,7 @@ function GetProxyEnabledWebClient
85
101
{
86
102
$wc = New-Object System.Net.WebClient
87
103
$proxy = [System.Net.WebRequest ]::GetSystemWebProxy()
88
- $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
104
+ $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
89
105
$wc.Proxy = $proxy
90
106
return $wc
91
107
}
@@ -96,6 +112,9 @@ if(!$PSScriptRoot){
96
112
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
97
113
}
98
114
115
+ if (! $Script ){
116
+ $Script = Join-Path $PSScriptRoot " build.cake"
117
+ }
99
118
$TOOLS_DIR = Join-Path $PSScriptRoot " tools"
100
119
$ADDINS_DIR = Join-Path $TOOLS_DIR " Addins"
101
120
$MODULES_DIR = Join-Path $TOOLS_DIR " Modules"
@@ -107,10 +126,14 @@ $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
107
126
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR " packages.config"
108
127
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR " packages.config"
109
128
129
+ $env: CAKE_PATHS_TOOLS = $TOOLS_DIR
130
+ $env: CAKE_PATHS_ADDINS = $ADDINS_DIR
131
+ $env: CAKE_PATHS_MODULES = $MODULES_DIR
132
+
110
133
# Make sure tools folder exists
111
134
if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
112
135
Write-Verbose - Message " Creating tools directory..."
113
- New-Item - Path $TOOLS_DIR - Type directory | out-null
136
+ New-Item - Path $TOOLS_DIR - Type Directory | Out-Null
114
137
}
115
138
116
139
# Make sure that packages.config exist.
@@ -146,25 +169,37 @@ if (!(Test-Path $NUGET_EXE)) {
146
169
}
147
170
}
148
171
172
+ # These are automatic variables in PowerShell Core, but not in Windows PowerShell 5.x
173
+ if (-not (Test-Path variable:global:ismacos)) {
174
+ $IsLinux = $false
175
+ $IsMacOS = $false
176
+ }
177
+
149
178
# Save nuget.exe path to environment to be available to child processed
150
- $ENV: NUGET_EXE = $NUGET_EXE
179
+ $env: NUGET_EXE = $NUGET_EXE
180
+ $env: NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS ) {
181
+ " mono `" $NUGET_EXE `" "
182
+ } else {
183
+ " `" $NUGET_EXE `" "
184
+ }
151
185
152
186
# Restore tools from NuGet?
153
187
if (-Not $SkipToolPackageRestore.IsPresent ) {
154
188
Push-Location
155
189
Set-Location $TOOLS_DIR
156
190
157
191
# Check for changes in packages.config and remove installed tools if true.
158
- [string ] $md5Hash = MD5HashFile( $PACKAGES_CONFIG )
192
+ [string ] $md5Hash = MD5HashFile $PACKAGES_CONFIG
159
193
if ((! (Test-Path $PACKAGES_CONFIG_MD5 )) -Or
160
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
194
+ ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
161
195
Write-Verbose - Message " Missing or changed package.config hash..."
162
196
Get-ChildItem - Exclude packages.config, nuget.exe , Cake.Bakery |
163
- Remove-Item - Recurse
197
+ Remove-Item - Recurse - Force
164
198
}
165
199
166
200
Write-Verbose - Message " Restoring tools from NuGet..."
167
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
201
+
202
+ $NuGetOutput = Invoke-Expression " & $env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
168
203
169
204
if ($LASTEXITCODE -ne 0 ) {
170
205
Throw " An error occurred while restoring NuGet tools."
@@ -173,7 +208,7 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
173
208
{
174
209
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
175
210
}
176
- Write-Verbose - Message ($NuGetOutput | out-string )
211
+ Write-Verbose - Message ($NuGetOutput | Out-String )
177
212
178
213
Pop-Location
179
214
}
@@ -184,13 +219,13 @@ if (Test-Path $ADDINS_PACKAGES_CONFIG) {
184
219
Set-Location $ADDINS_DIR
185
220
186
221
Write-Verbose - Message " Restoring addins from NuGet..."
187
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
222
+ $NuGetOutput = Invoke-Expression " & $ env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
188
223
189
224
if ($LASTEXITCODE -ne 0 ) {
190
225
Throw " An error occurred while restoring NuGet addins."
191
226
}
192
227
193
- Write-Verbose - Message ($NuGetOutput | out-string )
228
+ Write-Verbose - Message ($NuGetOutput | Out-String )
194
229
195
230
Pop-Location
196
231
}
@@ -201,13 +236,13 @@ if (Test-Path $MODULES_PACKAGES_CONFIG) {
201
236
Set-Location $MODULES_DIR
202
237
203
238
Write-Verbose - Message " Restoring modules from NuGet..."
204
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
239
+ $NuGetOutput = Invoke-Expression " & $ env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
205
240
206
241
if ($LASTEXITCODE -ne 0 ) {
207
242
Throw " An error occurred while restoring NuGet modules."
208
243
}
209
244
210
- Write-Verbose - Message ($NuGetOutput | out-string )
245
+ Write-Verbose - Message ($NuGetOutput | Out-String )
211
246
212
247
Pop-Location
213
248
}
@@ -217,20 +252,23 @@ if (!(Test-Path $CAKE_EXE)) {
217
252
Throw " Could not find Cake.exe at $CAKE_EXE "
218
253
}
219
254
255
+ $CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS ) {
256
+ " mono `" $CAKE_EXE `" "
257
+ } else {
258
+ " `" $CAKE_EXE `" "
259
+ }
220
260
221
-
222
- # Build Cake arguments
223
- $ cakeArguments = @ ( " $Script " );
224
- if ($Target ) { $cakeArguments += " -target=$Target " }
261
+ # Build an array (not a string) of Cake arguments to be joined later
262
+ $cakeArguments = @ ()
263
+ if ( $Script ) { $ cakeArguments += " `" $Script `" " }
264
+ if ($Target ) { $cakeArguments += " -target=`" $Target `" " }
225
265
if ($Configuration ) { $cakeArguments += " -configuration=$Configuration " }
226
266
if ($Verbosity ) { $cakeArguments += " -verbosity=$Verbosity " }
227
267
if ($ShowDescription ) { $cakeArguments += " -showdescription" }
228
268
if ($DryRun ) { $cakeArguments += " -dryrun" }
229
- if ($Experimental ) { $cakeArguments += " -experimental" }
230
- if ($Mono ) { $cakeArguments += " -mono" }
231
269
$cakeArguments += $ScriptArgs
232
270
233
271
# Start Cake
234
272
Write-Host " Running build script..."
235
- & $CAKE_EXE $ cakeArguments
273
+ Invoke-Expression " & $CAKE_EXE_INVOCATION $ ( $ cakeArguments -join " " ) "
236
274
exit $LASTEXITCODE
0 commit comments