< Summary - Kestrun — Combined Coverage

Information
Class: Public.Service.Set-KrServiceDescriptor
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Set-KrServiceDescriptor.ps1
Tag: Kestrun/Kestrun@6135d944f8787fb570e4dfbacac6e80312799a86
Line coverage
84%
Covered lines: 65
Uncovered lines: 12
Coverable lines: 77
Total lines: 218
Line coverage: 84.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 03/26/2026 - 03:54:59 Line coverage: 83.5% (56/67) Total lines: 187 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d04/19/2026 - 15:52:57 Line coverage: 84.4% (65/77) Total lines: 218 Tag: Kestrun/Kestrun@765a8f13c573c01494250a29d6392b6037f087c9

Coverage delta

Coverage delta 1 -1

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Set-KrServiceDescriptor.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Updates a Service.psd1 descriptor file.
 4.DESCRIPTION
 5    Updates Description, Version, EntryPoint, ServiceLogPath, PreservePaths, and ApplicationDataFolders values in Servic
 6    Name is immutable and cannot be changed by this cmdlet.
 7.PARAMETER Path
 8    Descriptor path. Accepts either a descriptor file path or a directory path.
 9    When a directory path is provided, Service.psd1 is appended automatically.
 10.PARAMETER Description
 11    New description value.
 12.PARAMETER Version
 13    New version value compatible with System.Version.
 14.PARAMETER EntryPoint
 15    New entry point path value.
 16.PARAMETER ServiceLogPath
 17    New default service log path.
 18.PARAMETER ClearServiceLogPath
 19    Removes ServiceLogPath from the descriptor.
 20.PARAMETER PreservePaths
 21    Replaces PreservePaths with a new list of relative file/folder paths.
 22.PARAMETER ClearPreservePaths
 23    Removes PreservePaths from the descriptor.
 24.PARAMETER ApplicationDataFolders
 25    Replaces ApplicationDataFolders with a new list of relative application-data folder paths.
 26.PARAMETER ClearApplicationDataFolders
 27    Removes ApplicationDataFolders from the descriptor.
 28.PARAMETER WhatIf
 29    Shows what would happen if the cmdlet runs. The cmdlet is not executed.
 30.PARAMETER Confirm
 31    Prompts for confirmation before running the cmdlet.
 32.EXAMPLE
 33    Set-KrServiceDescriptor -Path .\Service.psd1 -Description 'Updated' -Version 1.2.1
 34#>
 35function Set-KrServiceDescriptor {
 36    [KestrunRuntimeApi('Everywhere')]
 37    [CmdletBinding(SupportsShouldProcess)]
 38    [OutputType([pscustomobject])]
 39    param(
 40        [Parameter()]
 41        [ValidateNotNullOrEmpty()]
 42        [string]$Path = 'Service.psd1',
 43
 44        [Parameter()]
 45        [string]$Description,
 46
 47        [Parameter()]
 48        [version]$Version,
 49
 50        [Parameter()]
 51        [string]$EntryPoint,
 52
 53        [Parameter()]
 54        [string]$ServiceLogPath,
 55
 56        [Parameter()]
 57        [string[]]$PreservePaths,
 58
 59        [Parameter()]
 60        [string[]]$ApplicationDataFolders,
 61
 62        [Parameter()]
 63        [switch]$ClearServiceLogPath,
 64
 65        [Parameter()]
 66        [switch]$ClearPreservePaths,
 67
 68        [Parameter()]
 69        [switch]$ClearApplicationDataFolders
 70    )
 71
 172    $updateRequested = $PSBoundParameters.ContainsKey('Description') -or
 73    $PSBoundParameters.ContainsKey('Version') -or
 74    $PSBoundParameters.ContainsKey('EntryPoint') -or
 75    $PSBoundParameters.ContainsKey('ServiceLogPath') -or
 76    $PSBoundParameters.ContainsKey('PreservePaths') -or
 77    $PSBoundParameters.ContainsKey('ApplicationDataFolders') -or
 78    $ClearServiceLogPath -or
 79    $ClearPreservePaths -or
 80    $ClearApplicationDataFolders
 81
 182    if (-not $updateRequested) {
 083        throw 'No updates requested. Specify one or more updatable fields.'
 84    }
 85
 186    if ($PSBoundParameters.ContainsKey('ServiceLogPath') -and $ClearServiceLogPath) {
 087        throw 'Cannot use -ServiceLogPath and -ClearServiceLogPath together.'
 88    }
 89
 190    if ($PSBoundParameters.ContainsKey('PreservePaths') -and $ClearPreservePaths) {
 091        throw 'Cannot use -PreservePaths and -ClearPreservePaths together.'
 92    }
 93
 194    if ($PSBoundParameters.ContainsKey('ApplicationDataFolders') -and $ClearApplicationDataFolders) {
 095        throw 'Cannot use -ApplicationDataFolders and -ClearApplicationDataFolders together.'
 96    }
 97
 198    $current = Get-KrServiceDescriptor -Path $Path
 99
 3100    $nextDescription = if ($PSBoundParameters.ContainsKey('Description')) { $Description } else { $current.Description }
 1101    $nextVersion = if ($PSBoundParameters.ContainsKey('Version')) {
 1102        if ($null -eq $Version) {
 1103            $null
 104        } else {
 1105            $Version.ToString()
 106        }
 107    } else {
 1108        $current.Version
 109    }
 3110    $nextEntryPoint = if ($PSBoundParameters.ContainsKey('EntryPoint')) { $EntryPoint } else { $current.EntryPoint }
 4111    $nextServiceLogPath = if ($ClearServiceLogPath) { $null } elseif ($PSBoundParameters.ContainsKey('ServiceLogPath')) 
 7112    $nextPreservePaths = if ($ClearPreservePaths) { @() } elseif ($PSBoundParameters.ContainsKey('PreservePaths')) { @($
 7113    $nextApplicationDataFolders = if ($ClearApplicationDataFolders) { @() } elseif ($PSBoundParameters.ContainsKey('Appl
 114
 1115    if ([string]::IsNullOrWhiteSpace($nextDescription)) {
 1116        if ($PSBoundParameters.ContainsKey('Description')) {
 1117            throw 'Parameter -Description cannot be null or empty.'
 118        }
 119
 1120        throw 'Service descriptor is missing a valid Description. Update the descriptor or pass -Description with a non-
 121    }
 122
 1123    if ([string]::IsNullOrWhiteSpace($nextVersion)) {
 1124        if ($PSBoundParameters.ContainsKey('Version')) {
 1125            throw 'Parameter -Version cannot be null or empty and must be compatible with [System.Version].'
 126        }
 127
 1128        throw 'Service descriptor is missing a valid Version. Pass -Version with a value compatible with [System.Version
 129    }
 130
 131    try {
 1132        [void][version]$nextVersion
 133    } catch {
 0134        if ($PSBoundParameters.ContainsKey('Version')) {
 0135            throw 'Parameter -Version cannot be null or empty and must be compatible with [System.Version].'
 136        }
 137
 0138        throw 'Service descriptor is missing a valid Version. Pass -Version with a value compatible with [System.Version
 139    }
 140
 1141    if ([string]::IsNullOrWhiteSpace($nextEntryPoint)) {
 0142        if ($PSBoundParameters.ContainsKey('EntryPoint')) {
 0143            throw 'Parameter -EntryPoint cannot be null or empty.'
 144        }
 145
 0146        throw 'Service descriptor is missing a valid EntryPoint. Update the descriptor or pass -EntryPoint with a non-em
 147    }
 148
 1149    if ([System.IO.Path]::IsPathRooted($nextEntryPoint)) {
 0150        throw "EntryPoint must be a relative path under the descriptor directory: $nextEntryPoint"
 151    }
 152
 1153    $descriptorDirectory = [System.IO.Path]::GetDirectoryName($current.Path)
 2154    $entryPointPath = [System.IO.Path]::GetFullPath((Join-Path -Path $descriptorDirectory -ChildPath $nextEntryPoint))
 2155    $descriptorRootWithSeparator = if ($descriptorDirectory.EndsWith([System.IO.Path]::DirectorySeparatorChar)) { $descr
 1156    if (-not $entryPointPath.StartsWith($descriptorRootWithSeparator, [System.StringComparison]::OrdinalIgnoreCase)) {
 0157        throw "EntryPoint must resolve to a file under descriptor path: $nextEntryPoint"
 158    }
 159
 2160    if (-not (Test-Path -LiteralPath $entryPointPath -PathType Leaf)) {
 1161        throw "EntryPoint file not found under descriptor path: $nextEntryPoint"
 162    }
 163
 1164    $escapedName = $current.Name.Replace("'", "''")
 1165    $escapedDescription = $nextDescription.Replace("'", "''")
 1166    $escapedVersion = $nextVersion.Replace("'", "''")
 167
 1168    $contentLines = [System.Collections.Generic.List[string]]::new()
 1169    $contentLines.Add('@{')
 1170    $contentLines.Add("    FormatVersion = '1.0'")
 1171    $contentLines.Add("    Name = '$escapedName'")
 1172    $contentLines.Add("    Description = '$escapedDescription'")
 1173    $contentLines.Add("    Version = '$escapedVersion'")
 174
 1175    $escapedEntryPoint = $nextEntryPoint.Replace("'", "''")
 1176    $contentLines.Add("    EntryPoint = '$escapedEntryPoint'")
 177
 1178    if (-not [string]::IsNullOrWhiteSpace($nextServiceLogPath)) {
 1179        $escapedServiceLogPath = $nextServiceLogPath.Replace("'", "''")
 1180        $contentLines.Add("    ServiceLogPath = '$escapedServiceLogPath'")
 181    }
 182
 1183    if ($null -ne $nextPreservePaths -and $nextPreservePaths.Count -gt 0) {
 1184        $contentLines.Add('    PreservePaths = @(')
 1185        foreach ($preservePath in $nextPreservePaths) {
 1186            if ([string]::IsNullOrWhiteSpace($preservePath)) {
 187                continue
 188            }
 189
 1190            $escapedPreservePath = $preservePath.Replace("'", "''")
 1191            $contentLines.Add("        '$escapedPreservePath'")
 192        }
 193
 1194        $contentLines.Add('    )')
 195    }
 196
 1197    if ($null -ne $nextApplicationDataFolders -and $nextApplicationDataFolders.Count -gt 0) {
 1198        $contentLines.Add('    ApplicationDataFolders = @(')
 1199        foreach ($applicationDataFolder in $nextApplicationDataFolders) {
 1200            if ([string]::IsNullOrWhiteSpace($applicationDataFolder)) {
 201                continue
 202            }
 203
 1204            $escapedApplicationDataFolder = $applicationDataFolder.Replace("'", "''")
 1205            $contentLines.Add("        '$escapedApplicationDataFolder'")
 206        }
 207
 1208        $contentLines.Add('    )')
 209    }
 210
 1211    $contentLines.Add('}')
 212
 1213    if ($PSCmdlet.ShouldProcess($current.Path, 'Update Service.psd1 descriptor (Name is immutable)')) {
 2214        Set-Content -LiteralPath $current.Path -Value ($contentLines -join [Environment]::NewLine) -Encoding utf8NoBOM
 215    }
 216
 1217    Get-KrServiceDescriptor -Path $current.Path
 218}

Methods/Properties

Set-KrServiceDescriptor()