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