2021-12-09 12:52:48 +03:00
#!/usr/bin/env pwsh
$DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1' ;
$DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
$PSScriptRoot = Split-Path $MyInvocation . MyCommand . Path -Parent
$BuildPath = Join-Path $PSScriptRoot " build "
2018-10-25 22:49:23 +03:00
2017-07-17 23:11:30 +03:00
# Make sure tools folder exists
$ToolPath = Join-Path $PSScriptRoot " tools "
if ( ! ( Test-Path $ToolPath ) ) {
Write-Verbose " Creating tools directory... "
2021-12-09 12:52:48 +03:00
New-Item -Path $ToolPath -Type Directory -Force | out-null
}
if ( $PSVersionTable . PSEdition -ne 'Core' ) {
# Attempt to set highest encryption available for SecurityProtocol.
# PowerShell will not set this by default (until maybe .NET 4.6.x). This
# will typically produce a message for PowerShell v2 (just an info
# message though)
try {
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
# installed (.NET 4.5 is an in-place upgrade).
[ System.Net.ServicePointManager ] :: SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
} catch {
Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3'
}
2017-07-17 23:11:30 +03:00
}
###########################################################################
# INSTALL .NET CORE CLI
###########################################################################
2021-12-09 12:52:48 +03:00
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX = 2
2017-07-17 23:11:30 +03:00
Function Remove-PathVariable([string]$VariableToRemove )
{
2021-12-09 12:52:48 +03:00
$SplitChar = ';'
if ( $IsMacOS -or $IsLinux ) {
$SplitChar = ':'
}
2017-07-17 23:11:30 +03:00
$path = [ Environment ] :: GetEnvironmentVariable ( " PATH " , " User " )
if ( $path -ne $null )
{
2021-12-09 12:52:48 +03:00
$newItems = $path . Split ( $SplitChar , [ StringSplitOptions ] :: RemoveEmptyEntries ) | Where-Object { " $( $_ ) " -inotlike $VariableToRemove }
[ Environment ] :: SetEnvironmentVariable ( " PATH " , [ System.String ] :: Join ( $SplitChar , $newItems ) , " User " )
2017-07-17 23:11:30 +03:00
}
$path = [ Environment ] :: GetEnvironmentVariable ( " PATH " , " Process " )
if ( $path -ne $null )
{
2021-12-09 12:52:48 +03:00
$newItems = $path . Split ( $SplitChar , [ StringSplitOptions ] :: RemoveEmptyEntries ) | Where-Object { " $( $_ ) " -inotlike $VariableToRemove }
[ Environment ] :: SetEnvironmentVariable ( " PATH " , [ System.String ] :: Join ( $SplitChar , $newItems ) , " Process " )
2017-07-17 23:11:30 +03:00
}
}
2021-12-09 12:52:48 +03:00
$InstallPath = Join-Path $PSScriptRoot " .dotnet "
$GlobalJsonPath = Join-Path $BuildPath " global.json "
if ( ! ( Test-Path $InstallPath ) ) {
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null ;
2017-07-17 23:11:30 +03:00
}
2021-12-09 12:52:48 +03:00
if ( $IsMacOS -or $IsLinux ) {
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
( New-Object System . Net . WebClient ) . DownloadFile ( $DotNetUnixInstallerUri , $ScriptPath ) ;
& bash $ScriptPath - -jsonfile " $GlobalJsonPath " - -install -dir " $InstallPath " - -no -path
2018-10-25 22:49:23 +03:00
Remove-PathVariable " $InstallPath "
2021-12-09 12:52:48 +03:00
$env:PATH = " $( $InstallPath ) : $env:PATH "
2018-10-25 22:49:23 +03:00
}
2021-12-09 12:52:48 +03:00
else {
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
( New-Object System . Net . WebClient ) . DownloadFile ( $DotNetInstallerUri , $ScriptPath ) ;
& $ScriptPath -JSonFile $GlobalJsonPath -InstallDir $InstallPath ;
2017-07-17 23:11:30 +03:00
2021-12-09 12:52:48 +03:00
Remove-PathVariable " $InstallPath "
$env:PATH = " $InstallPath ; $env:PATH "
2017-07-17 23:11:30 +03:00
}
2021-12-09 12:52:48 +03:00
$env:DOTNET_ROOT = $InstallPath
2017-07-17 23:11:30 +03:00
###########################################################################
# RUN BUILD SCRIPT
###########################################################################
2021-12-09 12:52:48 +03:00
& dotnet run - -project build / Build . csproj - - $args
2017-07-17 23:11:30 +03:00
2021-12-09 12:52:48 +03:00
exit $LASTEXITCODE ;