Modules/businessdev.ALbuild.Apps/Private/ConvertTo-BcAlcResponseArgs.ps1

function ConvertTo-BcAlcResponseArgs {
    <#
    .SYNOPSIS
        Converts an alc argument list into response-file lines (one argument per line, quoted as needed).
    .DESCRIPTION
        Pure helper (no I/O, unit-testable). The Container-engine compile can pass alc a very large
        argument list - one /packagecachepath per first-party symbol folder - which, on some artifact
        layouts, overflows the Windows command-line limit and fails with "The filename or extension is
        too long" (CreateProcess error 206). Passing the arguments through a response file
        ('alc @args.rsp') removes that limit: the compiler reads the file as if the arguments were on
        the command line.
 
        Each argument goes on its own line. An argument containing whitespace is wrapped in double
        quotes (the AL/Roslyn command-line parser splits unquoted lines on whitespace, so an unquoted
        '/packagecachepath:C:\Program Files\...' would break into two tokens). A trailing backslash run
        is doubled inside the quotes so it does not escape the closing quote. Empty entries are dropped.
    .PARAMETER Argument
        The alc arguments to write to the response file.
    .OUTPUTS
        System.String[] - the response-file lines.
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Returns the response-file argument lines; the plural noun is intentional.')]
    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [Parameter(Mandatory)] [AllowEmptyCollection()] [AllowNull()] [AllowEmptyString()] [string[]] $Argument
    )

    $lines = foreach ($a in $Argument) {
        if ([string]::IsNullOrEmpty($a)) { continue }
        if ($a -match '\s') {
            # Double a trailing backslash run so '...\' does not escape the closing quote.
            $escaped = $a -replace '(\\+)$', '$1$1'
            '"' + $escaped + '"'
        }
        else { $a }
    }
    return @($lines)
}