2018-04-30 18:57:52 +03:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
This is a Powershell script to bootstrap a Cake build.
|
|
|
|
.DESCRIPTION
|
|
|
|
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
|
|
|
|
and execute your Cake build script with the parameters you provide.
|
|
|
|
.PARAMETER Target
|
|
|
|
The build script target to run.
|
|
|
|
.PARAMETER Configuration
|
|
|
|
The build configuration to use.
|
|
|
|
.PARAMETER Verbosity
|
|
|
|
Specifies the amount of information to be displayed.
|
|
|
|
.PARAMETER WhatIf
|
|
|
|
Performs a dry run of the build script.
|
|
|
|
No tasks will be executed.
|
|
|
|
.PARAMETER ScriptArgs
|
|
|
|
Remaining arguments are added here.
|
|
|
|
.LINK
|
|
|
|
https://cakebuild.net
|
|
|
|
#>
|
|
|
|
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[string]$Target = "Default",
|
|
|
|
[ValidateSet("Release", "Debug")]
|
|
|
|
[string]$Configuration = "Release",
|
|
|
|
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
|
|
|
|
[string]$Verbosity = "Verbose",
|
|
|
|
[switch]$WhatIf,
|
|
|
|
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
|
|
|
|
[string[]]$ScriptArgs
|
|
|
|
)
|
|
|
|
|
|
|
|
$CakeVersion = "0.27.1"
|
|
|
|
$DotNetChannel = "Current";
|
2022-08-03 02:37:48 +03:00
|
|
|
$DotNetVersion = "6.0.302";
|
2018-04-30 18:57:52 +03:00
|
|
|
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
|
|
|
|
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
|
|
|
|
# Temporarily skip verification of addins.
|
|
|
|
$ENV:CAKE_SETTINGS_SKIPVERIFICATION='true'
|
2016-11-08 04:50:24 +03:00
|
|
|
|
|
|
|
# Make sure tools folder exists
|
2018-04-30 18:57:52 +03:00
|
|
|
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
2016-11-08 04:50:24 +03:00
|
|
|
$ToolPath = Join-Path $PSScriptRoot "tools"
|
|
|
|
if (!(Test-Path $ToolPath)) {
|
|
|
|
Write-Verbose "Creating tools directory..."
|
|
|
|
New-Item -Path $ToolPath -Type directory | out-null
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# INSTALL .NET CORE CLI
|
|
|
|
###########################################################################
|
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
Function Remove-PathVariable([string]$VariableToRemove)
|
|
|
|
{
|
|
|
|
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
|
|
|
|
if ($path -ne $null)
|
|
|
|
{
|
|
|
|
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
|
|
|
|
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
|
|
|
|
if ($path -ne $null)
|
|
|
|
{
|
|
|
|
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
|
|
|
|
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 04:50:24 +03:00
|
|
|
# Get .NET Core CLI path if installed.
|
|
|
|
$FoundDotNetCliVersion = $null;
|
|
|
|
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
|
|
|
|
$FoundDotNetCliVersion = dotnet --version;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($FoundDotNetCliVersion -ne $DotNetVersion) {
|
|
|
|
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
|
|
|
|
if (!(Test-Path $InstallPath)) {
|
|
|
|
mkdir -Force $InstallPath | Out-Null;
|
|
|
|
}
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
|
2018-04-30 18:57:52 +03:00
|
|
|
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
|
2016-11-08 04:50:24 +03:00
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
Remove-PathVariable "$InstallPath"
|
|
|
|
$env:PATH = "$InstallPath;$env:PATH"
|
2016-11-08 04:50:24 +03:00
|
|
|
}
|
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
|
|
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
|
|
|
|
|
2016-11-08 04:50:24 +03:00
|
|
|
###########################################################################
|
2018-04-30 18:57:52 +03:00
|
|
|
# INSTALL NUGET
|
2016-11-08 04:50:24 +03:00
|
|
|
###########################################################################
|
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
# Make sure nuget.exe exists.
|
|
|
|
$NugetPath = Join-Path $ToolPath "nuget.exe"
|
|
|
|
if (!(Test-Path $NugetPath)) {
|
|
|
|
Write-Host "Downloading NuGet.exe..."
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
|
2016-11-08 04:50:24 +03:00
|
|
|
}
|
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
###########################################################################
|
|
|
|
# INSTALL CAKE
|
|
|
|
###########################################################################
|
2016-11-08 04:50:24 +03:00
|
|
|
|
|
|
|
# Make sure Cake has been installed.
|
2018-04-30 18:57:52 +03:00
|
|
|
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe"
|
2016-11-08 04:50:24 +03:00
|
|
|
if (!(Test-Path $CakePath)) {
|
|
|
|
Write-Host "Installing Cake..."
|
2018-04-30 18:57:52 +03:00
|
|
|
Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Throw "An error occurred while restoring Cake from NuGet."
|
|
|
|
}
|
2016-11-08 04:50:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# RUN BUILD SCRIPT
|
|
|
|
###########################################################################
|
|
|
|
|
2018-04-30 18:57:52 +03:00
|
|
|
# Build the argument list.
|
|
|
|
$Arguments = @{
|
|
|
|
target=$Target;
|
|
|
|
configuration=$Configuration;
|
|
|
|
verbosity=$Verbosity;
|
|
|
|
dryrun=$WhatIf;
|
|
|
|
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };
|
|
|
|
|
|
|
|
# Start Cake
|
|
|
|
Write-Host "Running build script..."
|
|
|
|
Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs"
|
2016-11-08 04:50:24 +03:00
|
|
|
exit $LASTEXITCODE
|