@@ -4,12 +4,17 @@ This is a Powershell script to bootstrap a Cake build.
44. DESCRIPTION
55This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
66and execute your Cake build script with the parameters you provide.
7+
8+ . PARAMETER Script
9+ The build script to execute.
710. PARAMETER Target
811The build script target to run.
912. PARAMETER Configuration
1013The build configuration to use.
1114. PARAMETER Verbosity
1215Specifies the amount of information to be displayed.
16+ . PARAMETER Experimental
17+ Tells Cake to use the latest Roslyn release.
1318. PARAMETER WhatIf
1419Performs a dry run of the build script.
1520No tasks will be executed.
@@ -21,65 +26,113 @@ http://cakebuild.net
2126
2227[CmdletBinding ()]
2328Param (
29+ [string ]$Script = " build.cake" ,
2430 [string ]$Target = " Default" ,
2531 [ValidateSet (" Release" , " Debug" )]
2632 [string ]$Configuration = " Release" ,
2733 [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
2834 [string ]$Verbosity = " Verbose" ,
35+ [switch ]$Experimental ,
36+ [Alias (" DryRun" , " Noop" )]
2937 [switch ]$WhatIf ,
3038 [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
3139 [string []]$ScriptArgs
3240)
3341
34- $CakeVersion = " 0.22.0"
35- $NugetUrl = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
42+ $cakeVersion = " 0.26.0"
43+ $buildPath = " $PSScriptRoot /build"
44+ $proj = @"
45+ <Project Sdk="Microsoft.NET.Sdk">
46+ <PropertyGroup>
47+ <TargetFramework>netcoreapp2.0</TargetFramework>
48+ </PropertyGroup>
49+ <ItemGroup>
50+ <PackageReference Include="Cake.CoreCLR" Version="$cakeVersion " />
51+ </ItemGroup>
52+ </Project>
53+ "@
54+
55+ # #########################
56+ # Install .NET Core CLI
57+ # #########################
58+ $dotNetCoreVersion = " 2.0.0"
59+ $dotNetInstallerUri = " https://dot.net/dotnet-install.ps1"
60+ Function Remove-PathVariable ([string ]$variableToRemove )
61+ {
62+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
63+ if ($path -ne $null )
64+ {
65+ $newItems = $path.Split (' ;' , [StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $variableToRemove }
66+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " User" )
67+ }
3668
37- # Make sure tools folder exists
38- $PSScriptRoot = Split-Path $MyInvocation .MyCommand.Path - Parent
39- $ToolPath = Join-Path $PSScriptRoot " tools "
40- if ( ! ( Test-Path $ToolPath )) {
41- Write-Verbose " Creating tools directory... "
42- New-Item - Path $ToolPath - Type directory | out-null
69+ $path = [ Environment ]::GetEnvironmentVariable( " PATH " , " Process " )
70+ if ( $path -ne $null )
71+ {
72+ $newItems = $path .Split ( ' ; ' , [ StringSplitOptions ]::RemoveEmptyEntries) | Where-Object { " $ ( $_ ) " -inotlike $variableToRemove }
73+ [ Environment ]::SetEnvironmentVariable( " PATH " , [ System.String ]::Join( ' ; ' , $newItems ) , " Process " )
74+ }
4375}
4476
45- # ##########################################################################
46- # INSTALL NUGET
47- # ##########################################################################
77+ $installPath = Join-Path $PSScriptRoot " .dotnet"
78+ if (! (Test-Path $installPath )) {
79+ mkdir - Force $installPath | Out-Null ;
80+ }
81+ (New-Object System.Net.WebClient).DownloadFile($dotNetInstallerUri , " $installPath \dotnet-install.ps1" );
4882
49- # Make sure nuget.exe exists.
50- $NugetPath = Join-Path $ToolPath " nuget.exe"
51- if (! (Test-Path $NugetPath )) {
52- Write-Host " Downloading NuGet.exe..."
53- (New-Object System.Net.WebClient).DownloadFile($NugetUrl , $NugetPath );
83+ $foundDotNetCliVersion = $null ;
84+ if (Get-Command dotnet - ErrorAction SilentlyContinue) {
85+ $foundDotNetCliVersion = dotnet -- version;
5486}
87+ if ($foundDotNetCliVersion -eq $dotNetCoreVersion ) {
88+ Write-Host " .Net Core version $dotNetCoreVersion installed locally."
89+ }
90+ else {
91+ Write-Host " .Net Core version $dotNetCoreVersion not installated locally. Downloading..."
5592
56- # ##########################################################################
57- # INSTALL CAKE
58- # ##########################################################################
59-
60- # Make sure Cake has been installed.
61- $CakePath = Join-Path $ToolPath " Cake.$CakeVersion /Cake.exe"
62- if (! (Test-Path $CakePath )) {
63- Write-Host " Installing Cake..."
64- Invoke-Expression " &`" $NugetPath `" install Cake -Version $CakeVersion -OutputDirectory `" $ToolPath `" " | Out-Null ;
65- if ($LASTEXITCODE -ne 0 ) {
66- Throw " An error occured while restoring Cake from NuGet."
67- }
93+ & $installPath \dotnet- install.ps1 - Channel Current - Version $dotNetCoreVersion - InstallDir $installPath ;
94+
95+ Remove-PathVariable " $installPath "
96+ $env: PATH = " $installPath ;$env: PATH "
97+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
98+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
99+ }
100+
101+ # #########################
102+ # Install Cake
103+ # #########################
104+
105+ Write-Host " Preparing cake..."
106+ # Make sure tools folder exists*
107+ $toolsPath = Join-Path $PSScriptRoot " tools"
108+ if (! (Test-Path $toolsPath )) {
109+ Write-Host " Creating tools directory..."
110+ New-Item - Path $toolsPath - Type directory | out-null
68111}
112+ $proj | Out-File $toolsPath \cake.csproj
113+
114+ Push-Location $toolsPath
69115
70- # ##########################################################################
71- # RUN BUILD SCRIPT
72- # ##########################################################################
116+ dotnet restore -- packages ./
73117
74- # Build the argument list.
75- $Arguments = @ {
118+ Pop-Location
119+
120+ # #########################
121+ # Run buildscript
122+ # #########################
123+ Write-Host " Running build script..."
124+ $arguments = @ {
76125 target = $Target ;
77126 configuration = $Configuration ;
78127 verbosity = $Verbosity ;
79128 dryrun = $WhatIf ;
129+ NuGet_UseInProcessClient = $true ;
80130}.GetEnumerator() | % {" --{0}=`" {1}`" " -f $_.key , $_.value };
81131
82- # Start Cake
83- Write-Host " Running build script..."
84- Invoke-Expression " & `" $CakePath `" `" build.cake`" $Arguments $ScriptArgs "
85- exit $LASTEXITCODE
132+ Write-Host $toolsPath / cake.coreclr/ $cakeVersion / Cake.dll $Script $arguments $ScriptArgs
133+
134+ $env: CAKE_SETTINGS_SKIPVERIFICATION = $true
135+
136+ & dotnet $toolsPath / cake.coreclr/ $cakeVersion / Cake.dll $Script $arguments $ScriptArgs
137+
138+ exit $LASTEXITCODE
0 commit comments