1- $CakeVersion = " 0.17.0"
1+ <#
2+ . SYNOPSIS
3+ This is a Powershell script to bootstrap a Cake build.
4+ . DESCRIPTION
5+ This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
6+ and execute your Cake build script with the parameters you provide.
7+ . PARAMETER Target
8+ The build script target to run.
9+ . PARAMETER Configuration
10+ The build configuration to use.
11+ . PARAMETER Verbosity
12+ Specifies the amount of information to be displayed.
13+ . PARAMETER WhatIf
14+ Performs a dry run of the build script.
15+ No tasks will be executed.
16+ . PARAMETER ScriptArgs
17+ Remaining arguments are added here.
18+ . LINK
19+ https://cakebuild.net
20+ #>
21+
22+ [CmdletBinding ()]
23+ Param (
24+ [string ]$Target = " Default" ,
25+ [ValidateSet (" Release" , " Debug" )]
26+ [string ]$Configuration = " Release" ,
27+ [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
28+ [string ]$Verbosity = " Verbose" ,
29+ [switch ]$WhatIf ,
30+ [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
31+ [string []]$ScriptArgs
32+ )
33+
34+ $CakeVersion = " 0.26.1"
35+ $DotNetChannel = " Current" ;
236$DotNetVersion = " 1.0.1" ;
3- $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1" ;
37+ $DotNetInstallerUri = " https://dot.net/v1/dotnet-install.ps1" ;
38+ $NugetUrl = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
439
5- # Make sure tools folder exists
6- $PSScriptRoot = $pwd
40+ # Temporarily skip verification of addins.
41+ $ENV: CAKE_SETTINGS_SKIPVERIFICATION = ' true '
742
43+ # Make sure tools folder exists
44+ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
845$ToolPath = Join-Path $PSScriptRoot " tools"
946if (! (Test-Path $ToolPath )) {
1047 Write-Verbose " Creating tools directory..."
@@ -15,6 +52,23 @@ if (!(Test-Path $ToolPath)) {
1552# INSTALL .NET CORE CLI
1653# ##########################################################################
1754
55+ Function Remove-PathVariable ([string ]$VariableToRemove )
56+ {
57+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
58+ if ($path -ne $null )
59+ {
60+ $newItems = $path.Split (' ;' , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
61+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " User" )
62+ }
63+
64+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " Process" )
65+ if ($path -ne $null )
66+ {
67+ $newItems = $path.Split (' ;' , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
68+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " Process" )
69+ }
70+ }
71+
1872# Get .NET Core CLI path if installed.
1973$FoundDotNetCliVersion = $null ;
2074if (Get-Command dotnet - ErrorAction SilentlyContinue) {
@@ -27,50 +81,53 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
2781 mkdir - Force $InstallPath | Out-Null ;
2882 }
2983 (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath \dotnet-install.ps1" );
30- & $InstallPath \dotnet- install.ps1 - Channel preview - Version $DotNetVersion - InstallDir $InstallPath ;
31-
32- $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
33- $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
84+ & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
3485
35- & dotnet -- info
86+ Remove-PathVariable " $InstallPath "
87+ $env: PATH = " $InstallPath ;$env: PATH "
3688}
3789
90+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
91+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
92+
3893# ##########################################################################
39- # INSTALL CAKE
94+ # INSTALL NUGET
4095# ##########################################################################
4196
42- Add-Type - AssemblyName System.IO.Compression.FileSystem
43- Function Unzip {
44- param ([ string ] $zipfile , [ string ] $outpath )
45-
46- [ System.IO.Compression.ZipFile ]::ExtractToDirectory( $zipfile , $outpath )
97+ # Make sure nuget.exe exists.
98+ $NugetPath = Join-Path $ToolPath " nuget.exe "
99+ if ( ! ( Test-Path $NugetPath )) {
100+ Write-Host " Downloading NuGet.exe... "
101+ ( New-Object System.Net.WebClient).DownloadFile( $NugetUrl , $NugetPath );
47102}
48103
104+ # ##########################################################################
105+ # INSTALL CAKE
106+ # ##########################################################################
49107
50108# Make sure Cake has been installed.
51- $CakePath = Join-Path $ToolPath " Cake.CoreCLR. $CakeVersion /Cake.dll "
109+ $CakePath = Join-Path $ToolPath " Cake.$CakeVersion /Cake.exe "
52110if (! (Test-Path $CakePath )) {
53111 Write-Host " Installing Cake..."
54- (New-Object System.Net.WebClient).DownloadFile(" https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CakeVersion " , " $ToolPath \Cake.CoreCLR.zip" )
55- Unzip " $ToolPath \Cake.CoreCLR.zip" " $ToolPath /Cake.CoreCLR.$CakeVersion "
56- Remove-Item " $ToolPath \Cake.CoreCLR.zip"
57- }
58-
59- # ##########################################################################
60- # INSTALL NUGET
61- # ##########################################################################
62-
63- # Make sure NuGet has been installed.
64- $NugetPath = Join-Path $PSScriptRoot " .nuget/nuget.exe"
65- if (! (Test-Path $NugetPath )) {
66- Write-Host " Installing Nuget..."
67- (New-Object System.Net.WebClient).DownloadFile(" https://www.nuget.org/nuget.exe" , $NugetPath )
68- & " $NugetPath " update - self
112+ Invoke-Expression " &`" $NugetPath `" install Cake -Version $CakeVersion -OutputDirectory `" $ToolPath `" " | Out-Null ;
113+ if ($LASTEXITCODE -ne 0 ) {
114+ Throw " An error occurred while restoring Cake from NuGet."
115+ }
69116}
70117
71118# ##########################################################################
72119# RUN BUILD SCRIPT
73120# ##########################################################################
74121
75- & dotnet " $CakePath " $args
76- exit $LASTEXITCODE
122+ # Build the argument list.
123+ $Arguments = @ {
124+ // target = $Target ;
125+ configuration = $Configuration ;
126+ verbosity = $Verbosity ;
127+ dryrun = $WhatIf ;
128+ }.GetEnumerator() | % {" --{0}=`" {1}`" " -f $_.key , $_.value };
129+
130+ # Start Cake
131+ Write-Host " Running build script..."
132+ Invoke-Expression " & `" $CakePath `" `" build.cake`" $Arguments $ScriptArgs "
133+ exit $LASTEXITCODE
0 commit comments