1
- # #########################################################################
2
- # This is the Cake bootstrapper script for PowerShell.
3
- # This file was downloaded from https://github.com/cake-build/resources
4
- # Feel free to change this file to fit your needs.
5
- # #########################################################################
1
+ $SCRIPT_NAME = " recipe.cake"
6
2
7
- <#
3
+ Write-Host " Restoring .NET Core tools"
4
+ dotnet tool restore
5
+ if ($LASTEXITCODE -ne 0 ) { exit $LASTEXITCODE }
8
6
9
- . SYNOPSIS
10
- This is a Powershell script to bootstrap a Cake build.
7
+ Write-Host " Bootstrapping Cake"
8
+ dotnet cake $SCRIPT_NAME -- bootstrap
9
+ if ($LASTEXITCODE -ne 0 ) { exit $LASTEXITCODE }
11
10
12
- . DESCRIPTION
13
- This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14
- and execute your Cake build script with the parameters you provide.
15
-
16
- . PARAMETER Script
17
- The build script to execute.
18
- . PARAMETER Target
19
- The build script target to run.
20
- . PARAMETER Configuration
21
- The build configuration to use.
22
- . PARAMETER Verbosity
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.
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
- . PARAMETER SkipToolPackageRestore
33
- Skips restoring of packages.
34
- . PARAMETER ScriptArgs
35
- Remaining arguments are added here.
36
-
37
- . LINK
38
- https://cakebuild.net
39
-
40
- #>
41
-
42
- [CmdletBinding ()]
43
- Param (
44
- [string ]$Script = " recipe.cake" ,
45
- [string ]$Target = " Default" ,
46
- [ValidateSet (" Release" , " Debug" )]
47
- [string ]$Configuration = " Release" ,
48
- [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
49
- [string ]$Verbosity = " Verbose" ,
50
- [switch ]$ShowDescription ,
51
- [Alias (" WhatIf" , " Noop" )]
52
- [switch ]$DryRun ,
53
- [switch ]$Experimental ,
54
- [switch ]$Mono ,
55
- [switch ]$SkipToolPackageRestore ,
56
- [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
57
- [string []]$ScriptArgs
58
- )
59
-
60
- [Reflection.Assembly ]::LoadWithPartialName(" System.Security" ) | Out-Null
61
- function MD5HashFile ([string ] $filePath )
62
- {
63
- if ([string ]::IsNullOrEmpty($filePath ) -or ! (Test-Path $filePath - PathType Leaf))
64
- {
65
- return $null
66
- }
67
-
68
- [System.IO.Stream ] $file = $null ;
69
- [System.Security.Cryptography.MD5 ] $md5 = $null ;
70
- try
71
- {
72
- $md5 = [System.Security.Cryptography.MD5 ]::Create()
73
- $file = [System.IO.File ]::OpenRead($filePath )
74
- return [System.BitConverter ]::ToString($md5.ComputeHash ($file ))
75
- }
76
- finally
77
- {
78
- if ($file -ne $null )
79
- {
80
- $file.Dispose ()
81
- }
82
- }
83
- }
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
-
94
- Write-Host " Preparing to run build script..."
95
-
96
- if (! $PSScriptRoot ){
97
- $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
98
- }
99
-
100
- $TOOLS_DIR = Join-Path $PSScriptRoot " tools"
101
- $ADDINS_DIR = Join-Path $TOOLS_DIR " Addins"
102
- $MODULES_DIR = Join-Path $TOOLS_DIR " Modules"
103
- $NUGET_EXE = Join-Path $TOOLS_DIR " nuget.exe"
104
- $CAKE_EXE = Join-Path $TOOLS_DIR " Cake/Cake.exe"
105
- $NUGET_URL = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
106
- $PACKAGES_CONFIG = Join-Path $TOOLS_DIR " packages.config"
107
- $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR " packages.config.md5sum"
108
- $ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR " packages.config"
109
- $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR " packages.config"
110
-
111
- # Make sure tools folder exists
112
- if ((Test-Path $PSScriptRoot ) -and ! (Test-Path $TOOLS_DIR )) {
113
- Write-Verbose - Message " Creating tools directory..."
114
- New-Item - Path $TOOLS_DIR - Type directory | out-null
115
- }
116
-
117
- # Make sure that packages.config exist.
118
- if (! (Test-Path $PACKAGES_CONFIG )) {
119
- Write-Verbose - Message " Downloading packages.config..."
120
- try {
121
- $wc = GetProxyEnabledWebClient
122
- $wc.DownloadFile (" https://cakebuild.net/download/bootstrapper/packages" , $PACKAGES_CONFIG ) } catch {
123
- Throw " Could not download packages.config."
124
- }
125
- }
126
-
127
- # Try find NuGet.exe in path if not exists
128
- if (! (Test-Path $NUGET_EXE )) {
129
- Write-Verbose - Message " Trying to find nuget.exe in PATH..."
130
- $existingPaths = $Env: Path -Split ' ;' | Where-Object { (! [string ]::IsNullOrEmpty($_ )) -and (Test-Path $_ - PathType Container) }
131
- $NUGET_EXE_IN_PATH = Get-ChildItem - Path $existingPaths - Filter " nuget.exe" | Select - First 1
132
- if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName )) {
133
- Write-Verbose - Message " Found in PATH at $ ( $NUGET_EXE_IN_PATH.FullName ) ."
134
- $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
135
- }
136
- }
137
-
138
- # Try download NuGet.exe if not exists
139
- if (! (Test-Path $NUGET_EXE )) {
140
- Write-Verbose - Message " Downloading NuGet.exe..."
141
- try {
142
- $wc = GetProxyEnabledWebClient
143
- $wc.DownloadFile ($NUGET_URL , $NUGET_EXE )
144
- } catch {
145
- Throw " Could not download NuGet.exe."
146
- }
147
- }
148
-
149
- # Save nuget.exe path to environment to be available to child processed
150
- $ENV: NUGET_EXE = $NUGET_EXE
151
-
152
- # Restore tools from NuGet?
153
- if (-Not $SkipToolPackageRestore.IsPresent ) {
154
- Push-Location
155
- Set-Location $TOOLS_DIR
156
-
157
- # Check for changes in packages.config and remove installed tools if true.
158
- [string ] $md5Hash = MD5HashFile($PACKAGES_CONFIG )
159
- if ((! (Test-Path $PACKAGES_CONFIG_MD5 )) -Or
160
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
161
- Write-Verbose - Message " Missing or changed package.config hash..."
162
- Remove-Item * - Recurse - Exclude packages.config, nuget.exe
163
- }
164
-
165
- Write-Verbose - Message " Restoring tools from NuGet..."
166
- $NuGetOutput = Invoke-Expression " &`" $NUGET_EXE `" install -ExcludeVersion -OutputDirectory `" $TOOLS_DIR `" "
167
-
168
- if ($LASTEXITCODE -ne 0 ) {
169
- Throw " An error occurred while restoring NuGet tools."
170
- }
171
- else
172
- {
173
- $md5Hash | Out-File $PACKAGES_CONFIG_MD5 - Encoding " ASCII"
174
- }
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
-
211
- Pop-Location
212
- }
213
-
214
- # Make sure that Cake has been installed.
215
- if (! (Test-Path $CAKE_EXE )) {
216
- Throw " Could not find Cake.exe at $CAKE_EXE "
217
- }
218
-
219
- # Build Cake arguments
220
- $cakeArguments = @ (" $Script " );
221
- if ($Target ) { $cakeArguments += " -target=$Target " }
222
- if ($Configuration ) { $cakeArguments += " -configuration=$Configuration " }
223
- if ($Verbosity ) { $cakeArguments += " -verbosity=$Verbosity " }
224
- if ($ShowDescription ) { $cakeArguments += " -showdescription" }
225
- if ($DryRun ) { $cakeArguments += " -dryrun" }
226
- if ($Experimental ) { $cakeArguments += " -experimental" }
227
- if ($Mono ) { $cakeArguments += " -mono" }
228
- $cakeArguments += $ScriptArgs
229
-
230
- # Start Cake
231
- Write-Host " Running build script..."
232
- & $CAKE_EXE $cakeArguments
233
- exit $LASTEXITCODE
11
+ Write-Host " Running Build"
12
+ dotnet cake $SCRIPT_NAME @args
13
+ if ($LASTEXITCODE -ne 0 ) { exit $LASTEXITCODE }
0 commit comments