Modules/businessdev.ALbuild.Containers/Private/Get-BcHostBaseImage.ps1

function Get-BcHostBaseImage {
    <#
    .SYNOPSIS
        Returns the Business Central generic base image whose Windows version matches this host.
 
    .DESCRIPTION
        A Windows container in process isolation runs on the HOST kernel, so the image's Windows build
        has to match the host's. ALbuild used to hardcode ltsc2022 (Server 2022, build 20348), which is
        correct on a Server 2022 agent and wrong on anything newer.
 
        The failure that mismatch produces is not a refusal to start - the container comes up, Business
        Central installs, the service tier runs, apps publish. Only the KERNEL-mode part breaks: IIS is
        served by http.sys, a kernel driver, so the web client accepts TCP connections and then answers
        no HTTP request at all. Diagnosed at a customer on Server 2025 (build 26100) running an ltsc2022
        image: TCP reached 443 and 7046 on every path, while a plain GET on the web client root timed out
        and the web client logged nothing.
 
        Mapping is by host build number, newest first, so a future Windows release falls back to the
        newest tag we know rather than to the oldest. Non-Windows hosts cannot run these images at all;
        they get the ltsc2022 default so the caller fails on the missing Docker engine, not here.
 
    .EXAMPLE
        Get-BcHostBaseImage
        mcr.microsoft.com/businesscentral:ltsc2025 # on a Server 2025 / Windows 11 24H2 host
 
    .OUTPUTS
        System.String: the fully-qualified base image reference.
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param()

    $fallback = 'mcr.microsoft.com/businesscentral:ltsc2022'
    # OSVersion.Platform, not $IsWindows: that variable does not exist in Windows PowerShell 5.1, where
    # reading it throws under StrictMode - and the runner this decides for runs on 5.1.
    if ([System.Environment]::OSVersion.Platform -ne [System.PlatformID]::Win32NT) { return $fallback }

    $build = 0
    try { $build = [int][System.Environment]::OSVersion.Version.Build }
    catch { return $fallback }

    # 26100 = Server 2025 / Windows 11 24H2; 20348 = Server 2022; older hosts keep ltsc2022.
    if ($build -ge 26100) { return 'mcr.microsoft.com/businesscentral:ltsc2025' }
    return $fallback
}