< Summary - Kestrun — Combined Coverage

Information
Class: Private.Assembly.Add-KrAspNetCoreType
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Add-KrAspNetCoreType.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
71%
Covered lines: 25
Uncovered lines: 10
Coverable lines: 35
Total lines: 66
Line coverage: 71.4%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Add-KrAspNetCoreType.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Loads required ASP.NET Core assemblies for PowerShell usage.
 4    .PARAMETER Version
 5        The .NET version to target (e.g. net8, net9, net10).
 6#>
 7function Add-KrAspNetCoreType {
 8    [CmdletBinding()]
 9    [OutputType([bool])]
 10    param (
 11        [Parameter()]
 12        [ValidateSet('net8.0', 'net9.0', 'net10.0')]
 13        [string]$Version = 'net8.0'
 14    )
 115    $versionNumber = $Version -replace 'net(\d+).*', '$1'
 216    $dotnetPath = (Get-Command -Name 'dotnet' -ErrorAction Stop).Source
 217    $realDotnetPath = (Get-Item $dotnetPath).Target
 218    if (-not $realDotnetPath) { $realDotnetPath = $dotnetPath }elseif ($realDotnetPath -notmatch '^/') {
 19        # If the target is a relative path, resolve it from the parent of $dotnetPath
 020        $realDotnetPath = Join-Path -Path (Split-Path -Parent $dotnetPath) -ChildPath $realDotnetPath
 021        $realDotnetPath = [System.IO.Path]::GetFullPath($realDotnetPath)
 22    }
 123    $dotnetDir = Split-Path -Path $realDotnetPath -Parent
 124    if (-not $dotnetDir) {
 025        throw 'Could not determine the path to the dotnet executable.'
 26    }
 127    $baseDir = Join-Path -Path $dotnetDir -ChildPath 'shared\Microsoft.AspNetCore.App'
 228    if (-not (Test-Path -Path $baseDir -PathType Container)) {
 029        throw "ASP.NET Core shared framework not found at $baseDir."
 30    }
 531    $versionDirs = Get-ChildItem -Path $baseDir -Directory | Where-Object { $_.Name -like "$($versionNumber).*" } | Sort
 132    foreach ($verDir in $versionDirs) {
 133        $assemblies = @()
 34
 235        Get-ChildItem -Path $verDir.FullName -Filter 'Microsoft.*.dll' | ForEach-Object {
 136            if ($assemblies -notcontains $_.Name) {
 137                $assemblies += $_.Name
 38            }
 39        }
 140        $allFound = $true
 141        foreach ($asm in $assemblies) {
 142            $asmPath = Join-Path -Path $verDir.FullName -ChildPath $asm
 243            if (-not (Test-Path -Path $asmPath)) {
 044                Write-Verbose "Assembly $asm not found in $($verDir.FullName)"
 045                $allFound = $false
 46                break
 47            }
 48        }
 149        if ($allFound) {
 150            $result = $true
 151            foreach ($asm in $assemblies) {
 152                $asmPath = Join-Path -Path $verDir.FullName -ChildPath $asm
 253                $result = $result -and (Assert-KrAssemblyLoaded -AssemblyPath $asmPath)
 54            }
 255            Write-Verbose "Loaded ASP.NET Core assemblies from $($verDir.FullName)"
 156            return $result
 57        }
 058        return $false
 59    }
 60
 061    Write-Error "Could not find ASP.NET Core assemblies for version $Version in $baseDir."
 062    Write-Warning "Please download the Runtime $Version from https://dotnet.microsoft.com/en-us/download/dotnet/$version
 63
 064    throw "Microsoft.AspNetCore.App version $Version not found in $baseDir."
 65}
 66

Methods/Properties

Add-KrAspNetCoreType()