-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCheck-DotNetSdk.ps1
37 lines (34 loc) · 959 Bytes
/
Check-DotNetSdk.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
.SYNOPSIS
Checks whether the .NET Core SDK required by this repo is installed.
#>
[CmdletBinding()]
Param (
)
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
if (!$dotnet) {
# Nothing is installed.
Write-Output $false
exit 1
}
# We need to set the current directory so dotnet considers the SDK required by our global.json file.
Push-Location "$PSScriptRoot\.."
try {
dotnet -h 2>&1 | Out-Null
if (($LASTEXITCODE -eq 129) -or # On Linux
($LASTEXITCODE -eq -2147450751) # On Windows
) {
# These exit codes indicate no matching SDK exists.
Write-Output $false
exit 2
}
# The required SDK is already installed!
Write-Output $true
exit 0
} catch {
# I don't know why, but on some build agents (e.g. MicroBuild), an exception is thrown from the `dotnet` invocation when a match is not found.
Write-Output $false
exit 3
} finally {
Pop-Location
}