AL/New-ALAppDependency.ps1
<# .Synopsis Adds new dependency to app.json for current project .Description Adds the defined dependency to the app.json for the current project. .Parameter SourcePath Path to the current project .Parameter Id The dependent app id .Parameter Name The name of the dependent app .Parameter Publisher The publisher of the app .Parameter Version The version of the app .Example New-ALAppDependency -Id "00000000-0000-0000-0000-000000000000" -Name "testapp" -Publisher "test" -Version "1.0.0.0" #> function New-ALAppDependency { [CmdletBinding(SupportsShouldProcess, ConfirmImpact="low")] Param( [Parameter(Mandatory = $false)] [string]$SourcePath = (Get-Location), [Parameter(Mandatory = $true)] [guid]$Id, [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $true)] [string]$Publisher, [Parameter(Mandatory = $true)] [string]$Version ) if ($PSCmdlet.ShouldProcess("app.json", "adds new dependency to ")) { $compiler = Get-AppKeyValue -SourcePath $TestPath -KeyName 'runtime' $Dependency = New-Object PSObject if ($compiler -ge '4.3') { $Dependency | Add-Member -MemberType NoteProperty -Name id -Value $Id } else { $Dependency | Add-Member -MemberType NoteProperty -Name appId -Value $Id } $Dependency | Add-Member -MemberType NoteProperty -Name name -Value $Name $Dependency | Add-Member -MemberType NoteProperty -Name publisher -Value $Publisher $Dependency | Add-Member -MemberType NoteProperty -Name version -Value $Version $AppJson = Get-Content (Join-Path $SourcePath 'app.json') -Raw | ConvertFrom-Json if (!$AppJson.dependencies) { $AppJson.dependencies = @() } $AppJson.dependencies += $Dependency Set-Content (Join-Path $SourcePath 'app.json') (ConvertTo-Json $AppJson) } } |