DevOpsHandling/Get-AndInstallApp.ps1

function  Get-AndInstallApp {
    param (
        [Parameter(Mandatory = $true)]
        [string]$devOpsOrganization,
        [Parameter(Mandatory = $true)]
        [string]$devOpsFeed,
        [Parameter(Mandatory = $true)]
        [string]$devOpsArtifact,
        [Parameter(Mandatory = $true)]
        [string]$Version,
        [Parameter(Mandatory = $false)]
        [pscredential] $Credential,
        [switch]$useDevEndpoint
    )

    $appsDirectory = New-TempDirectory
    Get-DevOpsArtifactsFromFeed -devOpsOrganization $devOpsOrganization -devOpsFeed $devOpsFeed -devOpsArtifact $devOpsArtifact -destination $appsDirectory -version $Version

    # loop through all dependent apps and - if NAV-X - install from bottom up
    $appFolder = New-TempDirectory
    $mainapp = Get-ChildItem -Path $appsDirectory -filter '*.app' -File
    Extract-AppFileToFolder -appFilename $mainapp[0].FullName -appFolder $appFolder -generateAppJson | Out-Null

    # loop through dependencies and add apps to
    $appJson = Get-Content -Path (Join-Path $appFolder 'app.json') | ConvertFrom-Json
    if ($null -ne $appJson.dependencies) {
        foreach($dep in $appJson.dependencies) {
            if ($dep.Publisher -ne "Microsoft") {
                $tempVersion = [version]$dep.Version
                $depVersion = ("{0}.{1}.{2}" -f $tempVersion.Major, $tempVersion.Minor, $tempVersion.Build)
                $depArtifact = "$($dep.Name.ToLower().Replace(" ", "_"))_app"

                Get-AndInstallApp -devOpsOrganization $devOpsOrganization -devOpsFeed $devOpsFeed -devOpsArtifact $depArtifact -version $depVersion -useDevEndpoint:$useDevEndpoint -Credential $Credential
            }
        }

        $parameters = @{}
        if ($useDevEndpoint.IsPresent) {
            $parameters.Add('useDevEndpoint', $true)
            $parameters.Add('credential', $credential)
        }
        Publish-BcContainerApp -containerName $ContainerName -appFile $mainapp.FullName -sync -tenant "default" -skipVerification -ignoreIfAppexists -install @parameters
    }

    Remove-Item -Path $appFolder -Recurse -Force
    Remove-Item -Path $appsDirectory -Recurse -Force
}