5
5
# #########################################################################
6
6
7
7
<#
8
+
8
9
. SYNOPSIS
9
10
This is a Powershell script to bootstrap a Cake build.
11
+
10
12
. DESCRIPTION
11
13
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
12
14
and execute your Cake build script with the parameters you provide.
15
+
13
16
. PARAMETER Script
14
17
The build script to execute.
15
18
. PARAMETER Target
@@ -18,19 +21,22 @@ The build script target to run.
18
21
The build configuration to use.
19
22
. PARAMETER Verbosity
20
23
Specifies the amount of information to be displayed.
24
+ . PARAMETER ShowDescription
25
+ Shows description about tasks.
26
+ . PARAMETER DryRun
27
+ Performs a dry run.
21
28
. PARAMETER Experimental
22
- Tells Cake to use the latest Roslyn release.
23
- . PARAMETER WhatIf
24
- Performs a dry run of the build script.
25
- No tasks will be executed.
29
+ Uses the nightly builds of the Roslyn script engine.
26
30
. PARAMETER Mono
27
- Tells Cake to use the Mono scripting engine.
31
+ Uses the Mono Compiler rather than the Roslyn script engine.
28
32
. PARAMETER SkipToolPackageRestore
29
33
Skips restoring of packages.
30
34
. PARAMETER ScriptArgs
31
35
Remaining arguments are added here.
36
+
32
37
. LINK
33
- http://cakebuild.net
38
+ https://cakebuild.net
39
+
34
40
#>
35
41
36
42
[CmdletBinding ()]
@@ -41,9 +47,10 @@ Param(
41
47
[string ]$Configuration = " Release" ,
42
48
[ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
43
49
[string ]$Verbosity = " Verbose" ,
50
+ [switch ]$ShowDescription ,
51
+ [Alias (" WhatIf" , " Noop" )]
52
+ [switch ]$DryRun ,
44
53
[switch ]$Experimental ,
45
- [Alias (" DryRun" , " Noop" )]
46
- [switch ]$WhatIf ,
47
54
[switch ]$Mono ,
48
55
[switch ]$SkipToolPackageRestore ,
49
56
[Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
@@ -75,38 +82,31 @@ function MD5HashFile([string] $filePath)
75
82
}
76
83
}
77
84
85
+ function GetProxyEnabledWebClient
86
+ {
87
+ $wc = New-Object System.Net.WebClient
88
+ $proxy = [System.Net.WebRequest ]::GetSystemWebProxy()
89
+ $proxy.Credentials = [System.Net.CredentialCache ]::DefaultCredentials
90
+ $wc.Proxy = $proxy
91
+ return $wc
92
+ }
93
+
78
94
Write-Host " Preparing to run build script..."
79
95
80
96
if (! $PSScriptRoot ){
81
97
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
82
98
}
83
99
84
100
$TOOLS_DIR = Join-Path $PSScriptRoot " tools"
101
+ $ADDINS_DIR = Join-Path $TOOLS_DIR " Addins"
102
+ $MODULES_DIR = Join-Path $TOOLS_DIR " Modules"
85
103
$NUGET_EXE = Join-Path $TOOLS_DIR " nuget.exe"
86
104
$CAKE_EXE = Join-Path $TOOLS_DIR " Cake/Cake.exe"
87
105
$NUGET_URL = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
88
106
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR " packages.config"
89
107
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR " packages.config.md5sum"
90
-
91
- # Should we use mono?
92
- $UseMono = " " ;
93
- if ($Mono.IsPresent ) {
94
- Write-Verbose - Message " Using the Mono based scripting engine."
95
- $UseMono = " -mono"
96
- }
97
-
98
- # Should we use the new Roslyn?
99
- $UseExperimental = " " ;
100
- if ($Experimental.IsPresent -and ! ($Mono.IsPresent )) {
101
- Write-Verbose - Message " Using experimental version of Roslyn."
102
- $UseExperimental = " -experimental"
103
- }
104
-
105
- # Is this a dry run?
106
- $UseDryRun = " " ;
107
- if ($WhatIf.IsPresent ) {
108
- $UseDryRun = " -dryrun"
109
- }
108
+ $ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR " packages.config"
109
+ $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR " packages.config"
110
110
111
111
# Make sure tools folder exists
112
112
if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
@@ -116,16 +116,18 @@ if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
116
116
117
117
# Make sure that packages.config exist.
118
118
if (! (Test-Path $PACKAGES_CONFIG )) {
119
- Write-Verbose - Message " Downloading packages.config..."
120
- try { (New-Object System.Net.WebClient).DownloadFile(" http://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG ) } catch {
119
+ Write-Verbose - Message " Downloading packages.config..."
120
+ try {
121
+ $wc = GetProxyEnabledWebClient
122
+ $wc.DownloadFile (" https://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG ) } catch {
121
123
Throw " Could not download packages.config."
122
124
}
123
125
}
124
126
125
127
# Try find NuGet.exe in path if not exists
126
128
if (! (Test-Path $NUGET_EXE )) {
127
129
Write-Verbose - Message " Trying to find nuget.exe in PATH..."
128
- $existingPaths = $Env: Path -Split ' ;' | Where-Object { (! [string ]::IsNullOrEmpty($_ )) -and (Test-Path $_ ) }
130
+ $existingPaths = $Env: Path -Split ' ;' | Where-Object { (! [string ]::IsNullOrEmpty($_ )) -and (Test-Path $_ - PathType Container ) }
129
131
$NUGET_EXE_IN_PATH = Get-ChildItem - Path $existingPaths - Filter " nuget.exe" | Select - First 1
130
132
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName )) {
131
133
Write-Verbose - Message " Found in PATH at $ ( $NUGET_EXE_IN_PATH.FullName ) ."
@@ -137,7 +139,8 @@ if (!(Test-Path $NUGET_EXE)) {
137
139
if (! (Test-Path $NUGET_EXE )) {
138
140
Write-Verbose - Message " Downloading NuGet.exe..."
139
141
try {
140
- (New-Object System.Net.WebClient).DownloadFile($NUGET_URL , $NUGET_EXE )
142
+ $wc = GetProxyEnabledWebClient
143
+ $wc.DownloadFile ($NUGET_URL , $NUGET_EXE )
141
144
} catch {
142
145
Throw " Could not download NuGet.exe."
143
146
}
@@ -160,16 +163,51 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
160
163
}
161
164
162
165
Write-Verbose - Message " Restoring tools from NuGet..."
163
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -PreRelease - OutputDirectory `" $TOOLS_DIR `" -Source https://www.myget.org/F/cake/api/v3/index.json "
166
+ $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
164
167
165
168
if ($LASTEXITCODE -ne 0 ) {
166
- Throw " An error occured while restoring NuGet tools."
169
+ Throw " An error occurred while restoring NuGet tools."
167
170
}
168
171
else
169
172
{
170
173
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
171
174
}
172
175
Write-Verbose - Message ($NuGetOutput | out-string )
176
+
177
+ Pop-Location
178
+ }
179
+
180
+ # Restore addins from NuGet
181
+ if (Test-Path $ADDINS_PACKAGES_CONFIG ) {
182
+ Push-Location
183
+ Set-Location $ADDINS_DIR
184
+
185
+ Write-Verbose - Message " Restoring addins from NuGet..."
186
+ $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $ADDINS_DIR `" "
187
+
188
+ if ($LASTEXITCODE -ne 0 ) {
189
+ Throw " An error occurred while restoring NuGet addins."
190
+ }
191
+
192
+ Write-Verbose - Message ($NuGetOutput | out-string )
193
+
194
+ Pop-Location
195
+ }
196
+
197
+ # Restore modules from NuGet
198
+ if (Test-Path $MODULES_PACKAGES_CONFIG ) {
199
+ Push-Location
200
+ Set-Location $MODULES_DIR
201
+
202
+ Write-Verbose - Message " Restoring modules from NuGet..."
203
+ $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $MODULES_DIR `" "
204
+
205
+ if ($LASTEXITCODE -ne 0 ) {
206
+ Throw " An error occurred while restoring NuGet modules."
207
+ }
208
+
209
+ Write-Verbose - Message ($NuGetOutput | out-string )
210
+
173
211
Pop-Location
174
212
}
175
213
@@ -178,7 +216,20 @@ if (!(Test-Path $CAKE_EXE)) {
178
216
Throw " Could not find Cake.exe at $CAKE_EXE "
179
217
}
180
218
219
+
220
+
221
+ # Build Cake arguments
222
+ $cakeArguments = @ (" $Script " );
223
+ if ($Target ) { $cakeArguments += " -target=$Target " }
224
+ if ($Configuration ) { $cakeArguments += " -configuration=$Configuration " }
225
+ if ($Verbosity ) { $cakeArguments += " -verbosity=$Verbosity " }
226
+ if ($ShowDescription ) { $cakeArguments += " -showdescription" }
227
+ if ($DryRun ) { $cakeArguments += " -dryrun" }
228
+ if ($Experimental ) { $cakeArguments += " -experimental" }
229
+ if ($Mono ) { $cakeArguments += " -mono" }
230
+ $cakeArguments += $ScriptArgs
231
+
181
232
# Start Cake
182
233
Write-Host " Running build script..."
183
- Invoke-Expression " & `" $CAKE_EXE `" `" $Script `" -target= `" $Target `" -configuration= `" $Configuration `" -verbosity= `" $Verbosity `" $UseMono $UseDryRun $UseExperimental $ScriptArgs "
184
- exit $LASTEXITCODE
234
+ & $CAKE_EXE $cakeArguments
235
+ exit $LASTEXITCODE
0 commit comments