< 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@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
76%
Covered lines: 30
Uncovered lines: 9
Coverable lines: 39
Total lines: 80
Line coverage: 76.9%
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 09/08/2025 - 20:34:03 Line coverage: 71.4% (25/35) Total lines: 66 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7210/13/2025 - 16:52:37 Line coverage: 0% (0/35) Total lines: 66 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e12/21/2025 - 19:25:34 Line coverage: 0% (0/39) Total lines: 80 Tag: Kestrun/Kestrun@63eee3e6ff7662a7eb5bb3603d667daccb809f2d01/21/2026 - 17:07:46 Line coverage: 76.9% (30/39) Total lines: 80 Tag: Kestrun/Kestrun@3f6f61710c7ef7d5953cab578fe699c1e5e01a36

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 (e.g. symlink in same folder)
 020        $realDotnetPath = Join-Path -Path (Split-Path -Path $dotnetPath -Parent) -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
 32
 33    # Try each version directory until we find one with all required assemblies
 234    $verDir = $versionDirs | Select-Object -First 1
 135    if (-not $verDir) {
 036        Write-Error "Could not find ASP.NET Core assemblies for version $Version in $baseDir."
 037        Write-Warning "Please download the Runtime $Version from https://dotnet.microsoft.com/en-us/download/dotnet/$ver
 38
 039        throw "Microsoft.AspNetCore.App version $Version not found in $baseDir."
 40    }
 41
 42    # Collect required assemblies
 143    $assemblies = @()
 44
 145    Get-ChildItem -Path $verDir.FullName -Filter '*.dll' |
 146        Where-Object {
 147            $_.Name -like 'Microsoft.*.dll' -or
 48            $_.Name -eq 'System.IO.Pipelines.dll'
 149        } | ForEach-Object {
 150            if ($assemblies -notcontains $_.Name) {
 151                $assemblies += $_.Name
 52            }
 53        }
 54
 255    Write-Verbose "Collected assemblies: $($assemblies -join ', ')"
 56
 57    # Check if all required assemblies are present
 158    $allFound = $true
 159    foreach ($asm in $assemblies) {
 160        $asmPath = Join-Path -Path $verDir.FullName -ChildPath $asm
 261        if (-not (Test-Path -Path $asmPath)) {
 062            Write-Verbose "Assembly $asm not found in $($verDir.FullName)"
 063            $allFound = $false
 64            break
 65        }
 66    }
 67
 168    if (-not $allFound) { return $false }
 69
 70    # Load all assemblies
 171    $result = $true
 172    foreach ($asm in $assemblies) {
 173        $asmPath = Join-Path -Path $verDir.FullName -ChildPath $asm
 274        $result = $result -and (Assert-KrAssemblyLoaded -AssemblyPath $asmPath)
 75    }
 76
 277    Write-Verbose "Loaded ASP.NET Core assemblies from $($verDir.FullName)"
 178    return $result
 79}
 80

Methods/Properties

Add-KrAspNetCoreType()