AL/Get-RuntimePackage.ps1

<#
 .Synopsis
  Retrieves the runtime packages for apps
 .Description
  Retrieves the runtime packages for the current app from a container and codesigns it, if required by the Business Central version. It also retrieves the Test app
 .Parameter ContainerName
  Name of the container that has the apps
 .Parameter SourceFolder
  Folder to current project
 .Parameter outputFolder
  Location the apps should be saved to
 .Parameter pfxFile
  Codesign certificate file
 .Parameter pfxPassword
  Password for the certificate
 .Parameter TestApp
  Add this switch to retrieve the test app for the project as well
 .Example
  $Get-RuntimePackage -outputFolder "C:\Install" -pfxFile "C:\PfxFile.pfx" -pfxPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force) -TestApp
#>

function Get-RuntimePackage {
    param (
        [Parameter(Mandatory = $false)]
        [string] $ContainerName,
        [Parameter(Mandatory = $false)]
        [string] $SourceFolder = (Get-Location),
        [Parameter(Mandatory = $true)]
        [string] $outputFolder,
        [Parameter(Mandatory = $true)]
        [securestring] $pfxFile,
        [Parameter(Mandatory = $true)]
        [securestring] $pfxPassword,
        [switch] $TestApp
    )

    if ($null -eq $ContainerName -or $ContainerName -eq "") {
        $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name')
    }

    if (!(Test-Path $outputFolder)) {
        New-EmptyDirectory $outputFolder
    }

    $appJson = (Get-Content (Join-Path $SourceFolder 'app.json') -Raw | ConvertFrom-Json)
    $localPath = Join-Path $outputFolder ($appJson.Publisher + "_" + $appJson.Name + "_" + $appJson.Version + "_Runtime.app")
    $appFile = Get-NavContainerAppRuntimePackage -containerName $ContainerName -appName $appJson.name
    Copy-FileFromNavContainer -containerName $ContainerName -containerPath $appFile -localPath $localPath

    [version]$BCFallPlatform = '15.0.0.0'
    [version]$platform = Get-AppKeyValue -SourcePath $SourceFolder -KeyName 'platform'
    if ($platform -ge $BCFallPlatform) {
        Invoke-SignFile -containerName $ContainerName -FileName $localPath -pfxFile $pfxFile -pfxPassword $pfxPassword
    }

    if ($TestApp.IsPresent) {
        $localPath = Join-Path $outputFolder ($appJson.Publisher + "_" + $appJson.Name + " Tests_" + $appJson.Version + "_Runtime.app")
        $appFile = Get-NavContainerAppRuntimePackage $ContainerName -appName "$($appJson.name + ' Tests')"
        Copy-FileFromNavContainer -containerName $ContainerName -containerPath $appFile -localPath $localPath

        if ($platform -ge $BCFallPlatform) {
            Invoke-SignFile -containerName $ContainerName -FileName $localPath -pfxFile $pfxFile -pfxPassword $pfxPassword
        }
    }
}
Export-ModuleMember Get-RuntimePackage