AL/Invoke-BuildALAppPackage.ps1
function Invoke-BuildALAppPackage { Param( [Parameter(Mandatory=$false)] $SourcePath = (Get-Location), [Parameter(Mandatory=$false)] $ContainerName = (Split-Path $SourcePath -Leaf), [switch]$Install, [Parameter(Mandatory=$false)] $CompilerPath = '', [Parameter(Mandatory=$false)] [switch]$DoNotDownloadSymbols, [Parameter(Mandatory=$false)] [securestring] $pfxFile = $null, [Parameter(Mandatory=$false)] [securestring] $pfxPassword = $null, [switch] $SignApp ) if (!(Get-IsALRepo $SourcePath)) { "$SourcePath is not an AL repository" } if ($SignApp.IsPresent) { if ($null -eq $pfxFile -or $null -eq $pfxPassword) { throw "Missing Sign File parameters" } } Remove-Item -Path "$SourcePath/*.app" -Force if (!$DoNotDownloadSymbols.IsPresent) { Write-Host "Downloading Symbols" Get-Symbols -SourcePath $SourcePath -ContainerName $ContainerName -includeTestSymbols } if ($CompilerPath -eq '') { $CompilerPath = Get-CompilerFromContainer -ContainerName $ContainerName } [version]$platform = Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform' if ($platform.Major -ge 13) { if (Test-Path (Join-Path $SourcePath '.netpackages')) { Start-Process -FilePath $CompilerPath -ArgumentList (('/project:"{0}"' -f $SourcePath),('/packagecachepath:"{0}"' -f (Join-Path $SourcePath '.alpackages')),('/assemblyprobingpaths:"{0}"' -f (Join-Path $SourcePath '.netpackages'))) -Wait -NoNewWindow -PassThru } else { Start-Process -FilePath $CompilerPath -ArgumentList (('/project:"{0}"' -f $SourcePath),('/packagecachepath:"{0}"' -f (Join-Path $SourcePath '.alpackages'))) -Wait -NoNewWindow -PassThru } } else { Start-Process -FilePath $CompilerPath -ArgumentList (('/project:"{0}"' -f $SourcePath),('/packagecachepath:"{0}"' -f (Join-Path $SourcePath '.alpackages'))) -Wait -NoNewWindow -PassThru } if (!(Get-ChildItem -Path $SourcePath -Filter '*.app')){ Write-Error 'App not created' exit $false; } if ($SignApp.IsPresent) { Get-ChildItem -Path $SourcePath -Filter '*.app' | ForEach-Object { $AppFile = $_.FullName $AppFile Invoke-SignFile -ContainerName $ContainerName -FilenAme $_.FullName -pfxFile $pfxFile -pfxPassword $pfxPassword } } else { Get-ChildItem -Path $SourcePath -Filter '*.app' | ForEach-Object { $AppFile = $_.FullName $AppFile } } if (Test-Path (Join-Path $SourcePath '.netpackages')) { $session = Get-NavContainerSession $ContainerName $ContainerScipt = Invoke-Command -Session $session -ScriptBlock { Join-Path -ChildPath "\Service\Add-ins" -Path (Join-Path -ChildPath (Get-ChildItem -Path "C:\Program Files\Microsoft Dynamics NAV\")[0] -Path "C:\Program Files\Microsoft Dynamics NAV\") Test-Path (Join-Path -Path (Join-Path -ChildPath "\Service\Add-ins" -Path (Join-Path -ChildPath (Get-ChildItem -Path "C:\Program Files\Microsoft Dynamics NAV\")[0] -Path "C:\Program Files\Microsoft Dynamics NAV\")) -ChildPath '.netpackages') } $ServiceTierAddins = $ContainerScipt[0] $ServiceTierAddinsExist = $ContainerScipt[1] if (!$ServiceTierAddinsExist){ Copy-Item -Path (Join-Path $SourcePath '.netpackages') -Destination $ServiceTierAddins -Recurse -ToSession $session } } if ($Install.IsPresent) { if ($SignApp.IsPresent) { Publish-NavContainerApp -containerName $ContainerName -appFile $AppFile -sync -install } else { Publish-NavContainerApp -containerName $ContainerName -appFile $AppFile -skipVerification -sync -install } } } Export-ModuleMember -Function Invoke-BuildALAppPackage |