-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCheck-DotNetRuntime.ps1
41 lines (37 loc) · 1.14 KB
/
Check-DotNetRuntime.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
38
39
40
41
<#
.SYNOPSIS
Checks whether a given .NET Core runtime is installed.
#>
[CmdletBinding()]
Param (
[Parameter()]
[ValidateSet('Microsoft.AspNetCore.App','Microsoft.NETCore.App')]
[string]$Runtime='Microsoft.NETCore.App',
[Parameter(Mandatory=$true)]
[Version]$Version
)
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
if (!$dotnet) {
# Nothing is installed.
Write-Output $false
exit 1
}
Function IsVersionMatch {
Param(
[Parameter()]
$actualVersion
)
return $actualVersion -and
$Version.Major -eq $actualVersion.Major -and
$Version.Minor -eq $actualVersion.Minor -and
(($Version.Build -eq -1) -or ($Version.Build -eq $actualVersion.Build)) -and
(($Version.Revision -eq -1) -or ($Version.Revision -eq $actualVersion.Revision))
}
$installedRuntimes = dotnet --list-runtimes |? { $_.Split()[0] -ieq $Runtime } |% { $v = $null; [Version]::tryparse($_.Split()[1], [ref] $v); $v }
$matchingRuntimes = $installedRuntimes |? { IsVersionMatch -actualVersion $_ }
if (!$matchingRuntimes) {
Write-Output $false
exit 1
}
Write-Output $true
exit 0