@@ -21,42 +21,52 @@ The build script target to run.
2121The build configuration to use.
2222. PARAMETER Verbosity
2323Specifies 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.
3128. PARAMETER SkipToolPackageRestore
3229Skips restoring of packages.
3330. PARAMETER ScriptArgs
3431Remaining arguments are added here.
3532
3633. LINK
37- http ://cakebuild.net
34+ https ://cakebuild.net
3835
3936#>
4037
4138[CmdletBinding ()]
4239Param (
4340 [string ]$Script = " build.cake" ,
44- [string ]$Target = " Default" ,
45- [ValidateSet (" Release" , " Debug" )]
46- [string ]$Configuration = " Release" ,
41+ [string ]$Target ,
42+ [string ]$Configuration ,
4743 [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 ,
5548 [switch ]$SkipToolPackageRestore ,
5649 [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
5750 [string []]$ScriptArgs
5851)
5952
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+
6070[Reflection.Assembly ]::LoadWithPartialName(" System.Security" ) | Out-Null
6171function MD5HashFile ([string ] $filePath )
6272{
@@ -82,57 +92,53 @@ function MD5HashFile([string] $filePath)
8292 }
8393}
8494
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+
85104Write-Host " Preparing to run build script..."
86105
87106if (! $PSScriptRoot ){
88107 $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
89108}
90109
91110$TOOLS_DIR = Join-Path $PSScriptRoot " tools"
111+ $ADDINS_DIR = Join-Path $TOOLS_DIR " Addins"
112+ $MODULES_DIR = Join-Path $TOOLS_DIR " Modules"
92113$NUGET_EXE = Join-Path $TOOLS_DIR " nuget.exe"
93114$CAKE_EXE = Join-Path $TOOLS_DIR " Cake/Cake.exe"
94115$NUGET_URL = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
95116$PACKAGES_CONFIG = Join-Path $TOOLS_DIR " packages.config"
96117$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"
117120
118121# Make sure tools folder exists
119122if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
120123 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
122125}
123126
124127# Make sure that packages.config exist.
125128if (! (Test-Path $PACKAGES_CONFIG )) {
126129 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 {
128134 Throw " Could not download packages.config."
129135 }
130136}
131137
132138# Try find NuGet.exe in path if not exists
133139if (! (Test-Path $NUGET_EXE )) {
134140 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 ) }
136142 $NUGET_EXE_IN_PATH = Get-ChildItem - Path $existingPaths - Filter " nuget.exe" | Select - First 1
137143 if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName )) {
138144 Write-Verbose - Message " Found in PATH at $ ( $NUGET_EXE_IN_PATH.FullName ) ."
@@ -144,39 +150,82 @@ if (!(Test-Path $NUGET_EXE)) {
144150if (! (Test-Path $NUGET_EXE )) {
145151 Write-Verbose - Message " Downloading NuGet.exe..."
146152 try {
147- (New-Object System.Net.WebClient).DownloadFile($NUGET_URL , $NUGET_EXE )
153+ $wc = GetProxyEnabledWebClient
154+ $wc.DownloadFile ($NUGET_URL , $NUGET_EXE )
148155 } catch {
149156 Throw " Could not download NuGet.exe."
150157 }
151158}
152159
153160# 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+ }
155167
156168# Restore tools from NuGet?
157169if (-Not $SkipToolPackageRestore.IsPresent ) {
158170 Push-Location
159171 Set-Location $TOOLS_DIR
160172
161173 # Check for changes in packages.config and remove installed tools if true.
162- [string ] $md5Hash = MD5HashFile( $PACKAGES_CONFIG )
174+ [string ] $md5Hash = MD5HashFile $PACKAGES_CONFIG
163175 if ((! (Test-Path $PACKAGES_CONFIG_MD5 )) -Or
164- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
176+ ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
165177 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
167180 }
168181
169182 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 `" "
171185
172186 if ($LASTEXITCODE -ne 0 ) {
173- Throw " An error occured while restoring NuGet tools."
187+ Throw " An error occurred while restoring NuGet tools."
174188 }
175189 else
176190 {
177191 $md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
178192 }
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+
180229 Pop-Location
181230}
182231
@@ -185,7 +234,23 @@ if (!(Test-Path $CAKE_EXE)) {
185234 Throw " Could not find Cake.exe at $CAKE_EXE "
186235}
187236
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+
188253# Start Cake
189254Write-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