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" ;
1+ $CakeVersion = " 0.17.0"
332$DotNetVersion = " 1.0.1" ;
34- $DotNetInstallerUri = " https://dot.net/v1/dotnet-install.ps1" ;
35- $NugetUrl = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
36-
37- # Temporarily skip verification of addins.
38- $ENV: CAKE_SETTINGS_SKIPVERIFICATION = ' true'
3+ $DotNetInstallerUri = " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1" ;
394
405# Make sure tools folder exists
41- $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
6+ $PSScriptRoot = $pwd
7+
428$ToolPath = Join-Path $PSScriptRoot " tools"
439if (! (Test-Path $ToolPath )) {
4410 Write-Verbose " Creating tools directory..."
@@ -49,81 +15,62 @@ if (!(Test-Path $ToolPath)) {
4915# INSTALL .NET CORE CLI
5016# ##########################################################################
5117
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-
6918# Get .NET Core CLI path if installed.
7019$FoundDotNetCliVersion = $null ;
7120if (Get-Command dotnet - ErrorAction SilentlyContinue) {
7221 $FoundDotNetCliVersion = dotnet -- version;
7322}
7423
75- if ($FoundDotNetCliVersion -ne $DotNetVersion ) {
76- $InstallPath = Join-Path $PSScriptRoot " .dotnet"
77- if (! (Test-Path $InstallPath )) {
78- mkdir - Force $InstallPath | Out-Null ;
79- }
80- (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri , " $InstallPath \dotnet-install.ps1" );
81- & $InstallPath \dotnet- install.ps1 - Channel $DotNetChannel - Version $DotNetVersion - InstallDir $InstallPath ;
24+ # if($FoundDotNetCliVersion -ne $DotNetVersion) {
25+ # $InstallPath = Join-Path $PSScriptRoot ".dotnet"
26+ # if (!(Test-Path $InstallPath)) {
27+ # mkdir -Force $InstallPath | Out-Null;
28+ # }
29+ # (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
30+ # & $InstallPath\dotnet-install.ps1 -Channel preview -Version $DotNetVersion -InstallDir $InstallPath;
8231
83- Remove-PathVariable " $InstallPath "
84- $env: PATH = " $InstallPath ;$env: PATH "
85- }
32+ # $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
33+ # $env:DOTNET_CLI_TELEMETRY_OPTOUT=1
8634
87- $ env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
88- $ env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
35+ # & dotnet --info
36+ # }
8937
9038# ##########################################################################
91- # INSTALL NUGET
39+ # INSTALL CAKE
9240# ##########################################################################
9341
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 );
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 )
9947}
10048
101- # ##########################################################################
102- # INSTALL CAKE
103- # ##########################################################################
10449
10550# Make sure Cake has been installed.
106- $CakePath = Join-Path $ToolPath " Cake.$CakeVersion /Cake.exe "
51+ $CakePath = Join-Path $ToolPath " Cake.CoreCLR. $CakeVersion /Cake.dll "
10752if (! (Test-Path $CakePath )) {
10853 Write-Host " Installing Cake..."
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- }
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
11369}
11470
11571# ##########################################################################
11672# RUN BUILD SCRIPT
11773# ##########################################################################
11874
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
75+ & dotnet " $CakePath " $args
76+ exit $LASTEXITCODE
0 commit comments