Modules/businessdev.ALbuild.OnPrem/Public/Publish-BcDevExtension.ps1
|
function Publish-BcDevExtension { <# .SYNOPSIS Publishes an AL app to a Business Central server's development endpoint (licensed). .DESCRIPTION Uploads the .app to the BC development service endpoint (the same endpoint VS Code uses for 'Publish'), which publishes, synchronises and installs the app in one call. Requires a valid ALbuild license. .PARAMETER DevServerUrl The development service base URL, e.g. https://bcserver:7049. .PARAMETER ServerInstance The server instance name (the URL path segment). .PARAMETER AppFile Path to the .app file. .PARAMETER Credential Credential for the dev endpoint (Windows or BC user). .PARAMETER SchemaUpdateMode Schema update mode: synchronize (default), recreate or forcesync. .PARAMETER DependencyPublishingOption ignore (default), default or strict. #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string] $DevServerUrl, [Parameter(Mandatory)] [string] $ServerInstance, [Parameter(Mandatory)] [string] $AppFile, [Parameter(Mandatory)] [pscredential] $Credential, [ValidateSet('synchronize', 'recreate', 'forcesync')] [string] $SchemaUpdateMode = 'synchronize', [ValidateSet('ignore', 'default', 'strict')] [string] $DependencyPublishingOption = 'ignore' ) Assert-ALbuildLicensed -Feature 'OnPrem' if (-not (Test-Path -LiteralPath $AppFile)) { throw "App file not found: '$AppFile'." } if (-not $PSCmdlet.ShouldProcess($DevServerUrl, "Dev-publish $(Split-Path $AppFile -Leaf)")) { return } $url = "$($DevServerUrl.TrimEnd('/'))/$ServerInstance/dev/apps?SchemaUpdateMode=$SchemaUpdateMode&DependencyPublishingOption=$DependencyPublishingOption" $bytes = [System.IO.File]::ReadAllBytes((Resolve-Path -LiteralPath $AppFile).ProviderPath) Invoke-RestMethod -Uri $url -Method Post -Credential $Credential -Body $bytes -ContentType 'application/octet-stream' -ErrorAction Stop | Out-Null Write-ALbuildLog -Level Success "Dev-published '$(Split-Path $AppFile -Leaf)' to '$ServerInstance'." } |