AL/Install-NavAppFromVSCode.ps1

function Install-NavAppFromVSCode {
    Param (
        [Parameter(Mandatory=$false)]
        [string] $ContainerName = '',
        [Parameter(Mandatory=$false)]
        [string] $SourcePath = (Get-Location),
        [switch] $SkipVerification,
        [switch] $TenantScope
    )

    Write-Host -ForegroundColor Green "Starting installation of app"
    if ($ContainerName -eq "") {
        $ContainerName = Get-ContainerFromLaunchJson -LaunchJsonPath (Join-Path $SourcePath '.vscode\launch.json')
    }

    $appName = Get-AppKeyValue -SourcePath $SourcePath -KeyName "Name"
    $appVersion = Get-AppKeyValue -SourcePath $SourcePath -KeyName "Version"
    $appPublisher = Get-AppKeyValue -SourcePath $SourcePath -KeyName "Publisher"
    $appFile = Join-Path $SourcePath ($appPublisher + "_" + $appName + "_" + $appVersion + ".app")

    if (!(Test-Path $appFile -PathType Leaf)) {
        throw "App file not found"
    }

    Write-Host "Testing, if app is installed"
    if ($null -ne (Get-NavContainerAppInfo -containerName $ContainerName | Where-Object Name -like ("*{0}*" -f $appName))) {
        Write-Host "App is installed - removing app"
        UnPublish-NavContainerApp -containerName $ContainerName -appName $appName -unInstall
    } else {
        Write-Host "App is not installed"
    }

    Write-Host "Installing app"
    if (!$SkipVerification.IsPresent) {
        if ($TenantScope.IsPresent) {
            Publish-NavContainerApp -containerName $ContainerName -appFile $appFile -install -sync -tenant "default" -scope Tenant
        } else {
            Publish-NavContainerApp -containerName $ContainerName -appFile $appFile -install -sync
        }
    } else {
        if ($TenantScope.IsPresent) {
            Publish-NavContainerApp -containerName $ContainerName -appFile $appFile -sync -skipVerification -install -tenant "default" -scope Tenant
        } else {
            Publish-NavContainerApp -containerName $ContainerName -appFile $appFile -sync -skipVerification -install
        }
    }

    Write-Host -ForegroundColor Green "App is installed"
}
Export-ModuleMember Install-NavAppFromVSCode