|
| 1 | +#! /usr/bin/env pwsh |
| 2 | + |
| 3 | +#Requires -PSEdition Core |
| 4 | +#Requires -Version 7 |
| 5 | + |
| 6 | +param( |
| 7 | + [Parameter(Mandatory = $false)][string] $Filter = "*", |
| 8 | + [Parameter(Mandatory = $false)][string] $Job = "" |
| 9 | +) |
| 10 | + |
| 11 | +$ErrorActionPreference = "Stop" |
| 12 | +$ProgressPreference = "SilentlyContinue" |
| 13 | + |
| 14 | +$solutionPath = $PSScriptRoot |
| 15 | +$sdkFile = Join-Path $solutionPath "global.json" |
| 16 | + |
| 17 | +$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version |
| 18 | + |
| 19 | +$installDotNetSdk = $false |
| 20 | + |
| 21 | +if (($null -eq (Get-Command "dotnet" -ErrorAction SilentlyContinue)) -and ($null -eq (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue))) { |
| 22 | + Write-Host "The .NET SDK is not installed." |
| 23 | + $installDotNetSdk = $true |
| 24 | +} |
| 25 | +else { |
| 26 | + Try { |
| 27 | + $installedDotNetVersion = (dotnet --version 2>&1 | Out-String).Trim() |
| 28 | + } |
| 29 | + Catch { |
| 30 | + $installedDotNetVersion = "?" |
| 31 | + } |
| 32 | + |
| 33 | + if ($installedDotNetVersion -ne $dotnetVersion) { |
| 34 | + Write-Host "The required version of the .NET SDK is not installed. Expected $dotnetVersion." |
| 35 | + $installDotNetSdk = $true |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +if ($installDotNetSdk) { |
| 40 | + ${env:DOTNET_INSTALL_DIR} = Join-Path $PSScriptRoot ".dotnetcli" |
| 41 | + $sdkPath = Join-Path ${env:DOTNET_INSTALL_DIR} "sdk" $dotnetVersion |
| 42 | + |
| 43 | + if (-Not (Test-Path $sdkPath)) { |
| 44 | + if (-Not (Test-Path ${env:DOTNET_INSTALL_DIR})) { |
| 45 | + mkdir ${env:DOTNET_INSTALL_DIR} | Out-Null |
| 46 | + } |
| 47 | + [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12" |
| 48 | + |
| 49 | + if (($PSVersionTable.PSVersion.Major -ge 6) -And (-Not $IsWindows)) { |
| 50 | + $installScript = Join-Path ${env:DOTNET_INSTALL_DIR} "install.sh" |
| 51 | + Invoke-WebRequest "https://dot.net/v1/dotnet-install.sh" -OutFile $installScript -UseBasicParsing |
| 52 | + chmod +x $installScript |
| 53 | + & $installScript --jsonfile $sdkFile --install-dir ${env:DOTNET_INSTALL_DIR} --no-path |
| 54 | + } |
| 55 | + else { |
| 56 | + $installScript = Join-Path ${env:DOTNET_INSTALL_DIR} "install.ps1" |
| 57 | + Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile $installScript -UseBasicParsing |
| 58 | + & $installScript -JsonFile $sdkFile -InstallDir ${env:DOTNET_INSTALL_DIR} -NoPath |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | +else { |
| 63 | + ${env:DOTNET_INSTALL_DIR} = Split-Path -Path (Get-Command dotnet).Path |
| 64 | +} |
| 65 | + |
| 66 | +$dotnet = Join-Path ${env:DOTNET_INSTALL_DIR} "dotnet" |
| 67 | + |
| 68 | +if ($installDotNetSdk) { |
| 69 | + ${env:PATH} = "${env:DOTNET_INSTALL_DIR};${env:PATH}" |
| 70 | +} |
| 71 | + |
| 72 | +$benchmarks = (Join-Path $solutionPath "perf" "TodoApp.Benchmarks" "TodoApp.Benchmarks.csproj") |
| 73 | + |
| 74 | +Write-Host "Running benchmarks..." -ForegroundColor Green |
| 75 | + |
| 76 | +$additionalArgs = @() |
| 77 | + |
| 78 | +if (-Not [string]::IsNullOrEmpty($Filter)) { |
| 79 | + $additionalArgs += "--filter" |
| 80 | + $additionalArgs += $Filter |
| 81 | +} |
| 82 | + |
| 83 | +if (-Not [string]::IsNullOrEmpty($Job)) { |
| 84 | + $additionalArgs += "--job" |
| 85 | + $additionalArgs += $Job |
| 86 | +} |
| 87 | + |
| 88 | +& $dotnet run --project $benchmarks --configuration "Release" -- $additionalArgs |
0 commit comments