Modules/businessdev.ALbuild.RuntimePackages/Public/Get-BcRuntimePackageBuildPlan.ps1

function Get-BcRuntimePackageBuildPlan {
    <#
    .SYNOPSIS
        Determines which Business Central platform versions still need a runtime package built.
 
    .DESCRIPTION
        Given the candidate platform versions, the app's minimum supported version, and the set of
        already-built versions, returns the versions that need building - the "incremental" part of
        the batched runtime-package engine. Versions below the app's minimum, or already built, are
        excluded.
 
    .PARAMETER ArtifactVersion
        Candidate platform versions (e.g. from Find-BcArtifactUrl ... -Select All).
 
    .PARAMETER MinimumVersion
        The app's minimum supported version (typically app.json 'application'). Versions whose
        major is below this minimum's major are skipped. Default 0.0.0.0 (no minimum).
 
    .PARAMETER AlreadyBuilt
        Versions already built (present in Blob/feed) which should be skipped.
 
    .EXAMPLE
        Get-BcRuntimePackageBuildPlan -ArtifactVersion $versions -MinimumVersion '25.0.0.0' -AlreadyBuilt $built
 
    .OUTPUTS
        System.String - the platform versions to build, ascending.
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory)] [string[]] $ArtifactVersion,
        [string] $MinimumVersion = '0.0.0.0',
        [string[]] $AlreadyBuilt = @()
    )

    $minMajor = ([version](ConvertTo-BcVersion $MinimumVersion)).Major
    $builtSet = @{}
    foreach ($b in $AlreadyBuilt) { $builtSet["$b"] = $true }

    $plan = foreach ($version in $ArtifactVersion) {
        if ($builtSet.ContainsKey("$version")) { continue }
        if (([version](ConvertTo-BcVersion $version)).Major -lt $minMajor) { continue }
        $version
    }

    return @($plan | Sort-Object -Property @{ Expression = { ConvertTo-BcVersion $_ } })
}