2018-11-22 04:57:18 +01:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
2021-12-17 08:59:18 +01:00
|
|
|
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
|
2018-11-22 04:57:18 +01:00
|
|
|
[string[]]$BuildArguments
|
|
|
|
)
|
|
|
|
|
2021-03-19 01:35:17 +01:00
|
|
|
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2021-03-19 01:35:17 +01:00
|
|
|
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
|
2018-11-22 04:57:18 +01:00
|
|
|
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# CONFIGURATION
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
|
2021-12-17 08:59:18 +01:00
|
|
|
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2021-12-17 08:59:18 +01:00
|
|
|
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
|
2020-06-03 08:32:08 +02:00
|
|
|
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
|
2018-11-22 04:57:18 +01:00
|
|
|
$DotNetChannel = "Current"
|
|
|
|
$DotNetCliVersion = Get-Content DotnetCliVersion.txt
|
|
|
|
|
|
|
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
|
|
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
|
2021-03-19 01:35:17 +01:00
|
|
|
$env:DOTNET_MULTILEVEL_LOOKUP = 0
|
2018-11-22 04:57:18 +01:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# EXECUTION
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
function ExecSafe([scriptblock] $cmd) {
|
2021-03-28 06:18:58 +02:00
|
|
|
$global:LASTEXITCODE = 0
|
2018-11-22 04:57:18 +01:00
|
|
|
& $cmd
|
|
|
|
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$json = "{`"sdk`":{`"version`":`"$DotNetCliVersion`"}}"
|
|
|
|
Out-File -FilePath $DotNetGlobalFile -Encoding utf8 -InputObject $json
|
2021-12-17 08:59:18 +01:00
|
|
|
|
2018-11-22 04:57:18 +01:00
|
|
|
# If global.json exists, load expected version
|
|
|
|
if (Test-Path $DotNetGlobalFile) {
|
2021-12-17 08:59:18 +01:00
|
|
|
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
|
|
|
|
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
|
|
|
|
$DotNetVersion = $DotNetGlobal.sdk.version
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
2021-12-17 08:59:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
$DotNetDirectory = "$TempDirectory\dotnet-win"
|
|
|
|
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
|
|
|
|
|
2021-12-17 08:59:18 +01:00
|
|
|
# If dotnet CLI is installed globally and it matches requested version, use for execution
|
2018-11-22 04:57:18 +01:00
|
|
|
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
|
2021-12-17 08:59:18 +01:00
|
|
|
$(dotnet --version) -eq $DotNetVersion) {
|
2018-11-22 04:57:18 +01:00
|
|
|
$env:DOTNET_EXE = (Get-Command "dotnet").Path
|
|
|
|
}
|
2021-12-17 08:59:18 +01:00
|
|
|
# If dotnet CLI is installed locally and it matches requested version, use for execution
|
2020-06-03 08:32:08 +02:00
|
|
|
elseif ($null -eq (Get-Command $env:DOTNET_EXE -ErrorAction SilentlyContinue) -or `
|
2021-12-17 08:59:18 +01:00
|
|
|
!(Test-Path variable:DotNetVersion) -or $(& $env:DOTNET_EXE --version) -ne $DotNetVersion) {
|
2018-11-22 04:57:18 +01:00
|
|
|
|
|
|
|
# Download install script
|
|
|
|
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
|
2020-06-03 08:32:08 +02:00
|
|
|
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
2018-11-22 04:57:18 +01:00
|
|
|
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
|
|
|
|
|
|
|
|
# Install by channel or version
|
|
|
|
if (!(Test-Path variable:DotNetVersion)) {
|
2021-12-17 08:59:18 +01:00
|
|
|
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
|
|
|
|
} else {
|
|
|
|
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
2021-12-17 08:59:18 +01:00
|
|
|
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
|
|
|
|
|
2021-03-19 01:35:17 +01:00
|
|
|
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
|
|
|
|
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
2019-02-17 02:03:56 +01:00
|
|
|
catch {
|
|
|
|
Write-Output $_.Exception.Message
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
finally {
|
|
|
|
if (Test-Path $DotNetGlobalFile) {
|
|
|
|
Remove-Item $DotNetGlobalFile
|
|
|
|
}
|
|
|
|
}
|