AL/Get-ALDependenciesFromAppJson.ps1
<#
.Synopsis Gets the dependency apps that are defined in the app.json .Description If app.json has dependent apps defined, it will download and install the apps, if possible .Parameter SourcePath Path to the current project .Parameter devOpsToken Token to access Azure DevOps. Can be provided in settings.json .Parameter ContainerName If blank, the container name will be retrieved from settings.json .Parameter skipVerification Add this switch to skip app verification for dependency apps .Parameter Install Add this switch to install the dependency apps .Parameter TenantScope Add this switch to install the dependency apps in the tenant and not global scope .Example $dependencies = Get-ALDependenciesFromAppJson #> function Get-ALDependenciesFromAppJson { Param( [Parameter(Mandatory = $true)] $appJson, [Parameter(Mandatory = $true)] [string]$sourcePath, [Parameter(Mandatory = $true)] [string] $devOpsToken, [Parameter(Mandatory = $false)] [string]$containerName, [Parameter(Mandatory = $false)] [switch] $skipVerification, [Parameter(Mandatory = $false)] [switch] $Install, [switch] $TenantScope ) foreach ($Dependency in $appJson.dependencies | Where-Object Name -NotLike '*Test*' | Where-Object Name -NotLike '*Runtime*') { if ($null -ne $Dependency) { $envDependency = (Get-DependencyFromEnvironment -sourcePath $sourcePath -name $Dependency.name) if ($null -ne $envDependency) { Write-Output "Getting dependencies for $($envDependency.name)" $apps = Get-DevOpsArtifactList -devOpsOrganization $envDependency.organization -devOpsFeed $envDependency.devOpsFeed -devOpsArtifactName $envDependency.devOpsArtifactName -version $envDependency.version -devOpsToken $devOpsToken -destination (Join-Path $sourcePath ".alpackages") if ($null -eq $envDependency.branchName) { $dependencyAppJson = Get-AppJsonForProjectAndRepo -devOpsOrganization $envDependency.organization -devOpsProjectName $envDependency.project -repositoryName $envDependency.repo -devOpsToken $devOpsToken } else { $dependencyAppJson = Get-AppJsonForProjectAndRepo -devOpsOrganization $envDependency.organization -devOpsProjectName $envDependency.project -repositoryName $envDependency.repo -devOpsToken $devOpsToken -branchName $envDependency.branchName } } else { if ($Dependency.publisher -eq 'Microsoft') { $Apps = @() $DependencyAppJson = $null #ConvertFrom-Json '{}' } } # get dependencies for dependency app if ($null -ne $DependencyAppJson) { Get-ALDependenciesFromAppJson -AppJson $dependencyAppJson -sourcePath $sourcePath -devOpsToken $devOpsToken -containerName $containerName -skipVerification:$skipVerification -Install:$Install } # copy and install apps foreach ($app in $apps) { Write-Output "Processing artifact $app" if ($Install.IsPresent) { try { $publishParameters = @{ containerName = $containerName appFile = $app install = $true sync = $true } if ($TenantScope.IsPresent) { $publishParameters.Add('scope', 'Tenant') $publishParameters.Add('tenant', 'Default') } $publishParameters.Add('skipVerification', $true) Publish-NavContainerApp @publishParameters } catch { if (!($_.Exception.Message.Contains('already published'))) { throw $_.Exception.Message } } } } } } } Export-ModuleMember Get-ALDependenciesFromAppJson |