Functions/New-BcRuntimePackage.ps1

<#
    .SYNOPSIS
    Creates a runtime package of a published app.
 
    .DESCRIPTION
    Creates a runtime package of a published app.
 
    .EXAMPLE
    $Apps | ForEach-Object {
    New-BcRuntimePackage `
        -ServerInstance 'ServerInstance' `
        -VersionManagementCodeunit '11012623' `
        -ShowMyCode $True `
        -RuntimePackagePath 'D:\Spring99NL candidate runtime\Extensions' `
        -Name $_.Name `
        -Version $_.Version `
        -Publisher $_.Publisher
    }
    .PARAMETER ServerInstance
    The Name of the server instance where the app is published.
 
    .PARAMETER VersionManagementCodeunit
    The id of the codeunit which has a function to get the release code of 4PS Construct.
 
    .PARAMETER Publisher
    The Publisher of the app.
 
    .PARAMETER Name
    The Name of the app.
 
    .PARAMETER Version
    The Version of the app.
 
    .PARAMETER ShowMyCode
    Determines if code could be seen from the app file (debugging alowed).
 
    .PARAMETER RuntimePackagePath
    The path where the new app file is created (directory).
#>


function New-BcRuntimePackage
{

    Param
    (
        [Parameter(Mandatory=$true)]
        [string] $ServerInstance,
        [Parameter(Mandatory=$true)]
        [int] $VersionManagementCodeunit,
        [Parameter(Mandatory=$true)]
        [string] $Publisher,
        [Parameter(Mandatory=$true)]
        [string] $Name,
        [Parameter(Mandatory=$true)]
        [string] $Version, 
        [Parameter(Mandatory=$true)]
        [bool] $ShowMyCode, 
        [Parameter(Mandatory=$true)]
        [string] $RuntimePackagePath,

        [string] $Tenant = 'default'
    )

    Process
    {
        Invoke-NAVCodeunit `
            -ServerInstance $ServerInstance `
            -Tenant $Tenant `
            -CodeunitId $VersionManagementCodeunit `
            -MethodName ReleaseMessage `
            -WarningVariable Release `
            -WarningAction Ignore

        $RuntimePackageName = "{0}_{1}_{2}_{3}_runtime.app" -f `
            $Publisher, `
            $Name, `
            (Get-LastLineFromArray -TextVariable $Release), `
            $Version 

        $RuntimePackagePath = Join-Path $RuntimePackagePath -ChildPath $RuntimePackageName 

        Get-NAVAppRuntimePackage `
            -ServerInstance $ServerInstance `
            -Tenant $Tenant `
            -Name $Name `
            -Version $Version `
            -Path $RuntimePackagePath `
            -ShowMyCode $ShowMyCode
    }
}

Export-ModuleMember -Function New-BcRuntimePackage