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 Configuration
8+ The build configuration to use.
9+ . PARAMETER Verbosity
10+ Specifies the amount of information to be displayed.
11+ . PARAMETER WhatIf
12+ Performs a dry run of the build script.
13+ No tasks will be executed.
14+ . PARAMETER ScriptArgs
15+ Remaining arguments are added here.
16+ . LINK
17+ https://cakebuild.net
18+ #>
19+
20+ [CmdletBinding ()]
21+ Param (
22+ [ValidateSet (" Release" , " Debug" )]
23+ [string ]$Configuration = " Release" ,
24+ [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
25+ [string ]$Verbosity = " Verbose" ,
26+ [switch ]$WhatIf ,
27+ [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
28+ [string []]$ScriptArgs
29+ )
30+
31+ $CakeVersion = " 0.26.1"
32+ $DotNetChannel = " Current" ;
233$DotNetVersion = " 1.0.1" ;
3- $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1" ;
34+ $DotNetInstallerUri = " https://dot.net/v1/dotnet-install.ps1" ;
35+ $NugetUrl = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
436
5- # Make sure tools folder exists
6- $PSScriptRoot = $pwd
37+ # Temporarily skip verification of addins.
38+ $ENV: CAKE_SETTINGS_SKIPVERIFICATION = ' true '
739
40+ # Make sure tools folder exists
41+ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
842$ToolPath = Join-Path $PSScriptRoot " tools"
943if (! (Test-Path $ToolPath )) {
1044 Write-Verbose " Creating tools directory..."
@@ -15,6 +49,23 @@ if (!(Test-Path $ToolPath)) {
1549# INSTALL .NET CORE CLI
1650# ##########################################################################
1751
52+ Function Remove-PathVariable ([string ]$VariableToRemove )
53+ {
54+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
55+ if ($path -ne $null )
56+ {
57+ $newItems = $path.Split (' ;' , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
58+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " User" )
59+ }
60+
61+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " Process" )
62+ if ($path -ne $null )
63+ {
64+ $newItems = $path.Split (' ;' , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $VariableToRemove }
65+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " Process" )
66+ }
67+ }
68+
1869# Get .NET Core CLI path if installed.
1970$FoundDotNetCliVersion = $null ;
2071if (Get-Command dotnet - ErrorAction SilentlyContinue) {
@@ -27,50 +78,52 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
2778 mkdir - Force $InstallPath | Out-Null ;
2879 }
2980 (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
81+ & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
3482
35- & dotnet -- info
83+ Remove-PathVariable " $InstallPath "
84+ $env: PATH = " $InstallPath ;$env: PATH "
3685}
3786
87+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
88+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
89+
3890# ##########################################################################
39- # INSTALL CAKE
91+ # INSTALL NUGET
4092# ##########################################################################
4193
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 )
94+ # Make sure nuget.exe exists.
95+ $NugetPath = Join-Path $ToolPath " nuget.exe "
96+ if ( ! ( Test-Path $NugetPath )) {
97+ Write-Host " Downloading NuGet.exe... "
98+ ( New-Object System.Net.WebClient).DownloadFile( $NugetUrl , $NugetPath );
4799}
48100
101+ # ##########################################################################
102+ # INSTALL CAKE
103+ # ##########################################################################
49104
50105# Make sure Cake has been installed.
51- $CakePath = Join-Path $ToolPath " Cake.CoreCLR. $CakeVersion /Cake.dll "
106+ $CakePath = Join-Path $ToolPath " Cake.$CakeVersion /Cake.exe "
52107if (! (Test-Path $CakePath )) {
53108 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
109+ Invoke-Expression " &`" $NugetPath `" install Cake -Version $CakeVersion -OutputDirectory `" $ToolPath `" " | Out-Null ;
110+ if ($LASTEXITCODE -ne 0 ) {
111+ Throw " An error occurred while restoring Cake from NuGet."
112+ }
69113}
70114
71115# ##########################################################################
72116# RUN BUILD SCRIPT
73117# ##########################################################################
74118
75- & dotnet " $CakePath " $args
76- exit $LASTEXITCODE
119+ # Build the argument list.
120+ $Arguments = @ {
121+ configuration = $Configuration ;
122+ verbosity = $Verbosity ;
123+ dryrun = $WhatIf ;
124+ }.GetEnumerator() | % {" --{0}=`" {1}`" " -f $_.key , $_.value };
125+
126+ # Start Cake
127+ Write-Host " Running build script..."
128+ Invoke-Expression " & `" $CakePath `" `" build.cake`" $Arguments $ScriptArgs "
129+ exit $LASTEXITCODE
0 commit comments