Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Check-DotNetRuntime.ps1 « tools - github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d0121095e9cdef78f9eb75a55cd48f09de6127f (plain)
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