Containers/New-ContainerFromVSCode.ps1
<#
.Synopsis Creates a new NAV/BC container .Description Creates a new NAV/BC container. It is intended to be used from VS Code .Parameter ContainerName Name of the container. Can be provided in the settings.json .Parameter SourcePath Path to the current project .Parameter SetupTestUsers Creates test users in the container after it is created .Parameter SkipTestTool Add this switch if you do not want to install the test tool .Parameter enableTaskScheduler Include this switch if you want to do Enable the Task Scheduler .Example New-ContainerFromVSCode -SetupTestUsers #> function New-ContainerFromVSCode { [CmdletBinding(SupportsShouldProcess, ConfirmImpact="low")] Param( [Parameter(Mandatory=$false)] $ContainerName = "", [Parameter(Mandatory=$false)] $SourcePath = (Get-Location), [switch] $SetupTestUsers, [switch] $SkipTestTool, [switch] $enableTaskScheduler ) if ($PSCmdlet.ShouldProcess("container", "This creates a new ")) { Write-Output -ForegroundColor Green "Creating new container for current project" if ($ContainerName -eq "") { $ContainerName = Get-ContainerFromLaunchJson } $locale = Get-EnvironmentKeyValue -KeyName 'locale' $startParameters = @{} [version]$platform = Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform' if ($platform.Major -le 14) { $startParameters.Add('includeCSide', $true) } if ($enableTaskScheduler.IsPresent) { $startParameters.Add('enableTaskScheduler', $true) } if ($SkipTestTool.IsPresent) { $startParameters.Add('SkipTestTool', $true) } New-Container -ContainerName $ContainerName -LicenseFile (Get-EnvironmentKeyValue -KeyName 'LocalLicenseFile') -alwaysPull -SetupTestUsers:$SetupTestUsers -Country $locale @startParameters if (!(Test-Path (Join-Path $SourcePath "tempDependency") -PathType Container)) { New-Item (Join-Path $SourcePath "tempDependency") -ItemType Directory -Force | Out-Null } Copy-Item (Join-Path $SourcePath "app.json") (Join-Path $SourcePath "tempDependency") Copy-Item (Join-Path $SourcePath "settings.json") (Join-Path $SourcePath "tempDependency") Get-ALDependency -ContainerName $ContainerName -SourcePath (Join-Path $SourcePath "tempDependency") -Install if (Test-Path (Join-Path $SourcePath "BaseObjects") -PathType Container) { Import-ObjectsFromFolder -ContainerName $ContainerName -Folder (Join-Path $SourcePath "BaseObjects") } if ($platform.Major -le 10) { Import-ObjectsFromFolder -ContainerName $ContainerName -Folder (Join-Path $SourcePath "src") } Remove-Item (Join-Path $SourcePath "tempDependency") -Recurse -Force Write-Output -ForegroundColor Green "Successfully created container $ContainerName" } } Export-ModuleMember New-ContainerFromVSCode |