@@ -21,42 +21,52 @@ The build script target to run.
21
21
The build configuration to use.
22
22
. PARAMETER Verbosity
23
23
Specifies the amount of information to be displayed.
24
- . PARAMETER Experimental
25
- Tells Cake to use the latest Roslyn release.
26
- . PARAMETER WhatIf
27
- Performs a dry run of the build script.
28
- No tasks will be executed.
29
- . PARAMETER Mono
30
- Tells Cake to use the Mono scripting engine.
24
+ . PARAMETER ShowDescription
25
+ Shows description about tasks.
26
+ . PARAMETER DryRun
27
+ Performs a dry run.
31
28
. PARAMETER SkipToolPackageRestore
32
29
Skips restoring of packages.
33
30
. PARAMETER ScriptArgs
34
31
Remaining arguments are added here.
35
32
36
33
. LINK
37
- http ://cakebuild.net
34
+ https ://cakebuild.net
38
35
39
36
#>
40
37
41
38
[CmdletBinding ()]
42
39
Param (
43
40
[string ]$Script = " build.cake" ,
44
- [string ]$Target = " Default" ,
45
- [ValidateSet (" Release" , " Debug" )]
46
- [string ]$Configuration = " Release" ,
41
+ [string ]$Target ,
42
+ [string ]$Configuration ,
47
43
[ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
48
- [string ]$Verbosity = " Verbose" ,
49
- [ValidateSet (" true" , " false" )]
50
- [string ]$PushPackages = " false" ,
51
- [switch ]$Experimental ,
52
- [Alias (" DryRun" , " Noop" )]
53
- [switch ]$WhatIf ,
54
- [switch ]$Mono ,
44
+ [string ]$Verbosity ,
45
+ [switch ]$ShowDescription ,
46
+ [Alias (" WhatIf" , " Noop" )]
47
+ [switch ]$DryRun ,
55
48
[switch ]$SkipToolPackageRestore ,
56
49
[Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
57
50
[string []]$ScriptArgs
58
51
)
59
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
+
60
70
[Reflection.Assembly ]::LoadWithPartialName(" System.Security" ) | Out-Null
61
71
function MD5HashFile ([string ] $filePath )
62
72
{
@@ -82,57 +92,53 @@ function MD5HashFile([string] $filePath)
82
92
}
83
93
}
84
94
95
+ function GetProxyEnabledWebClient
96
+ {
97
+ $wc = New-Object System.Net.WebClient
98
+ $proxy = [System.Net.WebRequest ]::GetSystemWebProxy()
99
+ $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
100
+ $wc.Proxy = $proxy
101
+ return $wc
102
+ }
103
+
85
104
Write-Host " Preparing to run build script..."
86
105
87
106
if (! $PSScriptRoot ){
88
107
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
89
108
}
90
109
91
110
$TOOLS_DIR = Join-Path $PSScriptRoot " tools"
111
+ $ADDINS_DIR = Join-Path $TOOLS_DIR " Addins"
112
+ $MODULES_DIR = Join-Path $TOOLS_DIR " Modules"
92
113
$NUGET_EXE = Join-Path $TOOLS_DIR " nuget.exe"
93
114
$CAKE_EXE = Join-Path $TOOLS_DIR " Cake/Cake.exe"
94
115
$NUGET_URL = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
95
116
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR " packages.config"
96
117
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR " packages.config.md5sum"
97
-
98
- # Should we use mono?
99
- $UseMono = " " ;
100
- if ($Mono.IsPresent ) {
101
- Write-Verbose - Message " Using the Mono based scripting engine."
102
- $UseMono = " -mono"
103
- }
104
-
105
- # Should we use the new Roslyn?
106
- $UseExperimental = " " ;
107
- if ($Experimental.IsPresent -and ! ($Mono.IsPresent )) {
108
- Write-Verbose - Message " Using experimental version of Roslyn."
109
- $UseExperimental = " -experimental"
110
- }
111
-
112
- # Is this a dry run?
113
- $UseDryRun = " " ;
114
- if ($WhatIf.IsPresent ) {
115
- $UseDryRun = " -dryrun"
116
- }
118
+ $ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR " packages.config"
119
+ $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR " packages.config"
117
120
118
121
# Make sure tools folder exists
119
122
if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
120
123
Write-Verbose - Message " Creating tools directory..."
121
- New-Item - Path $TOOLS_DIR - Type directory | out-null
124
+ New-Item - Path $TOOLS_DIR - Type Directory | Out-Null
122
125
}
123
126
124
127
# Make sure that packages.config exist.
125
128
if (! (Test-Path $PACKAGES_CONFIG )) {
126
129
Write-Verbose - Message " Downloading packages.config..."
127
- try { (New-Object System.Net.WebClient).DownloadFile(" http://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG ) } catch {
130
+ try {
131
+ $wc = GetProxyEnabledWebClient
132
+ $wc.DownloadFile (" https://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG )
133
+ } catch {
128
134
Throw " Could not download packages.config."
129
135
}
130
136
}
131
137
132
138
# Try find NuGet.exe in path if not exists
133
139
if (! (Test-Path $NUGET_EXE )) {
134
140
Write-Verbose - Message " Trying to find nuget.exe in PATH..."
135
- $existingPaths = $Env: Path -Split ' ;' | Where-Object { (! [string ]::IsNullOrEmpty($_ )) -and (Test-Path $_ ) }
141
+ $existingPaths = $Env: Path -Split ' ;' | Where-Object { (! [string ]::IsNullOrEmpty($_ )) -and (Test-Path $_ - PathType Container ) }
136
142
$NUGET_EXE_IN_PATH = Get-ChildItem - Path $existingPaths - Filter " nuget.exe" | Select - First 1
137
143
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName )) {
138
144
Write-Verbose - Message " Found in PATH at $ ( $NUGET_EXE_IN_PATH.FullName ) ."
@@ -144,39 +150,82 @@ if (!(Test-Path $NUGET_EXE)) {
144
150
if (! (Test-Path $NUGET_EXE )) {
145
151
Write-Verbose - Message " Downloading NuGet.exe..."
146
152
try {
147
- (New-Object System.Net.WebClient).DownloadFile($NUGET_URL , $NUGET_EXE )
153
+ $wc = GetProxyEnabledWebClient
154
+ $wc.DownloadFile ($NUGET_URL , $NUGET_EXE )
148
155
} catch {
149
156
Throw " Could not download NuGet.exe."
150
157
}
151
158
}
152
159
153
160
# Save nuget.exe path to environment to be available to child processed
154
- $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
+ }
155
167
156
168
# Restore tools from NuGet?
157
169
if (-Not $SkipToolPackageRestore.IsPresent ) {
158
170
Push-Location
159
171
Set-Location $TOOLS_DIR
160
172
161
173
# Check for changes in packages.config and remove installed tools if true.
162
- [string ] $md5Hash = MD5HashFile( $PACKAGES_CONFIG )
174
+ [string ] $md5Hash = MD5HashFile $PACKAGES_CONFIG
163
175
if ((! (Test-Path $PACKAGES_CONFIG_MD5 )) -Or
164
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
176
+ ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
165
177
Write-Verbose - Message " Missing or changed package.config hash..."
166
- Remove-Item * - Recurse - Exclude packages.config, nuget.exe
178
+ Get-ChildItem - Exclude packages.config, nuget.exe , Cake.Bakery |
179
+ Remove-Item - Recurse - Force
167
180
}
168
181
169
182
Write-Verbose - Message " Restoring tools from NuGet..."
170
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
183
+
184
+ $NuGetOutput = Invoke-Expression " & $env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
171
185
172
186
if ($LASTEXITCODE -ne 0 ) {
173
- Throw " An error occured while restoring NuGet tools."
187
+ Throw " An error occurred while restoring NuGet tools."
174
188
}
175
189
else
176
190
{
177
191
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
178
192
}
179
- Write-Verbose - Message ($NuGetOutput | out-string )
193
+ Write-Verbose - Message ($NuGetOutput | Out-String )
194
+
195
+ Pop-Location
196
+ }
197
+
198
+ # Restore addins from NuGet
199
+ if (Test-Path $ADDINS_PACKAGES_CONFIG ) {
200
+ Push-Location
201
+ Set-Location $ADDINS_DIR
202
+
203
+ Write-Verbose - Message " Restoring addins from NuGet..."
204
+ $NuGetOutput = Invoke-Expression " & $env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
205
+
206
+ if ($LASTEXITCODE -ne 0 ) {
207
+ Throw " An error occurred while restoring NuGet addins."
208
+ }
209
+
210
+ Write-Verbose - Message ($NuGetOutput | Out-String )
211
+
212
+ Pop-Location
213
+ }
214
+
215
+ # Restore modules from NuGet
216
+ if (Test-Path $MODULES_PACKAGES_CONFIG ) {
217
+ Push-Location
218
+ Set-Location $MODULES_DIR
219
+
220
+ Write-Verbose - Message " Restoring modules from NuGet..."
221
+ $NuGetOutput = Invoke-Expression " & $env: NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
222
+
223
+ if ($LASTEXITCODE -ne 0 ) {
224
+ Throw " An error occurred while restoring NuGet modules."
225
+ }
226
+
227
+ Write-Verbose - Message ($NuGetOutput | Out-String )
228
+
180
229
Pop-Location
181
230
}
182
231
@@ -185,7 +234,23 @@ if (!(Test-Path $CAKE_EXE)) {
185
234
Throw " Could not find Cake.exe at $CAKE_EXE "
186
235
}
187
236
237
+ $CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS ) {
238
+ " mono `" $CAKE_EXE `" "
239
+ } else {
240
+ " `" $CAKE_EXE `" "
241
+ }
242
+
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 `" " }
247
+ if ($Configuration ) { $cakeArguments += " -configuration=$Configuration " }
248
+ if ($Verbosity ) { $cakeArguments += " -verbosity=$Verbosity " }
249
+ if ($ShowDescription ) { $cakeArguments += " -showdescription" }
250
+ if ($DryRun ) { $cakeArguments += " -dryrun" }
251
+ $cakeArguments += $ScriptArgs
252
+
188
253
# Start Cake
189
254
Write-Host " Running build script..."
190
- Invoke-Expression " & `" $CAKE_EXE `" `" $Script `" -target= `" $Target `" -configuration= `" $Configuration `" -verbosity= `" $Verbosity `" -pushpackages= `" $PushPackages `" $UseMono $UseDryRun $UseExperimental $ScriptArgs "
191
- exit $LASTEXITCODE
255
+ Invoke-Expression " & $CAKE_EXE_INVOCATION $ ( $cakeArguments -join " " ) "
256
+ exit $LASTEXITCODE
0 commit comments