2018-11-24 19:12:59 +01:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
|
|
|
|
[string[]]$BuildArguments
|
|
|
|
)
|
|
|
|
|
2019-12-27 19:54:38 +01:00
|
|
|
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
|
2018-11-24 19:12:59 +01:00
|
|
|
|
|
|
|
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { exit 1 }
|
|
|
|
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# CONFIGURATION
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
|
|
|
|
$TempDirectory = "$PSScriptRoot\\.tmp"
|
|
|
|
|
|
|
|
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
|
|
|
|
$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
|
|
|
|
$DotNetChannel = "Current"
|
|
|
|
|
|
|
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
|
|
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# EXECUTION
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
function ExecSafe([scriptblock] $cmd) {
|
|
|
|
& $cmd
|
|
|
|
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
|
|
|
}
|
|
|
|
|
|
|
|
# If global.json exists, load expected version
|
|
|
|
if (Test-Path $DotNetGlobalFile) {
|
2019-12-27 19:54:38 +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-24 19:12:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
|
2019-12-27 19:54:38 +01:00
|
|
|
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
|
2018-11-24 19:12:59 +01:00
|
|
|
(!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) {
|
|
|
|
$env:DOTNET_EXE = (Get-Command "dotnet").Path
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$DotNetDirectory = "$TempDirectory\dotnet-win"
|
|
|
|
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
|
|
|
|
|
|
|
|
# Download install script
|
|
|
|
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
|
2019-12-27 19:54:38 +01:00
|
|
|
New-Item -ItemType Directory -Path $TempDirectory | Out-Null
|
2018-11-24 19:12:59 +01:00
|
|
|
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
|
|
|
|
|
|
|
|
# Install by channel or version
|
|
|
|
if (!(Test-Path variable:DotNetVersion)) {
|
|
|
|
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
|
|
|
|
} else {
|
|
|
|
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
|
|
|
|
|
2019-12-27 19:54:38 +01:00
|
|
|
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false }
|
|
|
|
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
|