diff --git a/AppHandling/Copy-AppFilesToFolder.ps1 b/AppHandling/Copy-AppFilesToFolder.ps1 index 72cbdfebb..8a5d1c3c3 100644 --- a/AppHandling/Copy-AppFilesToFolder.ps1 +++ b/AppHandling/Copy-AppFilesToFolder.ps1 @@ -11,10 +11,11 @@ #> function Copy-AppFilesToFolder { Param( + [Parameter(Mandatory=$true)] $appFiles, + [Parameter(Mandatory=$true)] [string] $folder ) - CopyAppFilesToFolder -appFiles $appFiles -folder $folder } Export-ModuleMember -Function Copy-AppFilesToFolder diff --git a/AppHandling/Get-TestsFromNavContainer.ps1 b/AppHandling/Get-TestsFromNavContainer.ps1 index d1b9c0f2d..cb1455d6c 100644 --- a/AppHandling/Get-TestsFromNavContainer.ps1 +++ b/AppHandling/Get-TestsFromNavContainer.ps1 @@ -171,7 +171,7 @@ try { } } -argumentList "01:00:00" - $result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests) + $result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests) $newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll" if (!(Test-Path $newtonSoftDllPath)) { diff --git a/AppHandling/Run-ConnectionTestToNavContainer.ps1 b/AppHandling/Run-ConnectionTestToNavContainer.ps1 index b4d70b55d..af70383b1 100644 --- a/AppHandling/Run-ConnectionTestToNavContainer.ps1 +++ b/AppHandling/Run-ConnectionTestToNavContainer.ps1 @@ -200,7 +200,7 @@ try { } else { - $result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [timespan] $interactionTimeout, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl) + $result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [timespan] $interactionTimeout, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl) $newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll" if (!(Test-Path $newtonSoftDllPath)) { diff --git a/AppHandling/Run-TestsInNavContainer.ps1 b/AppHandling/Run-TestsInNavContainer.ps1 index c26eb27b4..009fe3376 100644 --- a/AppHandling/Run-TestsInNavContainer.ps1 +++ b/AppHandling/Run-TestsInNavContainer.ps1 @@ -374,7 +374,7 @@ try { } } - $result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests) + $result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests) $newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll" if (!(Test-Path $newtonSoftDllPath)) { diff --git a/ContainerHandling/Enter-NavContainer.ps1 b/ContainerHandling/Enter-NavContainer.ps1 index c5b017fdf..ba0607817 100644 --- a/ContainerHandling/Enter-NavContainer.ps1 +++ b/ContainerHandling/Enter-NavContainer.ps1 @@ -23,7 +23,7 @@ function Enter-BcContainer { Enter-PSSession -Session $session if ($session.ComputerType -eq 'Container') { Invoke-Command -Session $session -ScriptBlock { - function prompt {"[$env:COMPUTERNAME]: PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "} + function prompt {"[$env:COMPUTERNAME]: PS5 $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "} } } } else { diff --git a/ContainerHandling/New-NavContainer.ps1 b/ContainerHandling/New-NavContainer.ps1 index 8dc5a607c..8e5a93f8a 100644 --- a/ContainerHandling/New-NavContainer.ps1 +++ b/ContainerHandling/New-NavContainer.ps1 @@ -497,6 +497,7 @@ try { Write-Host "BcContainerHelper is running inside a Container" } Write-Host "UsePsSession is $($bcContainerHelperConfig.UsePsSession)" + Write-Host "UsePwshForBc24 is $($bcContainerHelperConfig.UsePwshForBc24)" Write-Host "Host is $($os.Caption) - $hostOsVersion" $dockerProcess = (Get-Process "dockerd" -ErrorAction Ignore) @@ -1724,7 +1725,7 @@ Get-NavServerUser -serverInstance $ServerInstance -tenant default |? LicenseType if ($version.Major -ge 24) { (' -if (!(Get-Command "invoke-sqlcmd" -ErrorAction SilentlyContinue)) { Install-package SqlServer -Force -RequiredVersion 21.1.18256 | Out-Null } +if (!(Get-Command "invoke-sqlcmd" -ErrorAction SilentlyContinue)) { try { Write-Host "Installing SqlServer module"; Install-package SqlServer -Force -RequiredVersion 21.1.18256 | Out-Null } catch { Write-Host "Failed to install SqlServer module" } } ') | Add-Content -Path "$myfolder\HelperFunctions.ps1" } diff --git a/ContainerHandling/Open-NavContainer.ps1 b/ContainerHandling/Open-NavContainer.ps1 index e80e75368..9cc85e364 100644 --- a/ContainerHandling/Open-NavContainer.ps1 +++ b/ContainerHandling/Open-NavContainer.ps1 @@ -20,6 +20,7 @@ function Open-BcContainer { Process { $shell = 'powershell' + $ps = 'PS5' try { $inspect = docker inspect $containerName | ConvertFrom-Json $version = [Version]$inspect.Config.Labels.version @@ -29,11 +30,13 @@ function Open-BcContainer { } if ($version.Major -ge 24 -and $usePwsh) { $shell = 'pwsh' + $ps = 'PS7' } - $psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] PS '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the $vs Container PowerShell prompt'; Write-Host 'Microsoft Windows Version $($inspect.Config.Labels.osversion)'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent""" + throw 'x' + $psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] $ps '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the $vs Container PowerShell prompt'; Write-Host 'Microsoft Windows Version $($inspect.Config.Labels.osversion)'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent""" } catch { - $psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] PS '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; . 'c:\run\prompt.ps1'""" + $psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] $ps '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the ContainerHelper PowerShell prompt'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent""" } Start-Process "cmd.exe" @("/C";"docker exec -it $containerName $shell -noexit -command $psPrompt") } diff --git a/CreateScript.ps1 b/CreateScript.ps1 index 407dab344..d50caf4cd 100644 --- a/CreateScript.ps1 +++ b/CreateScript.ps1 @@ -320,7 +320,12 @@ if (($pswindow.BufferSize) -and ($pswindow.WindowSize) -and ($pswindow.WindowSiz $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) $randompw = Get-RandomPassword -$bestContainerOsVersion = [System.Version]((Get-BestGenericImageName).Split(':')[1]).Split('-')[0] +$os = (Get-CimInstance Win32_OperatingSystem) +if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) { + throw "Unknown Host Operating System" +} +$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR +$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR") $ErrorActionPreference = "STOP" $script:wizardStep = 0 @@ -1184,51 +1189,8 @@ $Step.SSL { $Step.Isolation { if ($hosting -eq "Local") { - - $os = (Get-CimInstance Win32_OperatingSystem) - if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) { - throw "Unknown Host Operating System" - } - - $UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR - $hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR") - - try { - $bestContainerOS = "The image, which matches your host OS best is $($bestContainerOsVersion.ToString())" - if ($hostOsVersion.Build -ge 20348 -and $bestContainerOsVersion.Build -ge 20348) { - if ($bestContainerOsVersion -le $hostOsVersion) { - $defaultIsolation = "process" - } - else { - $defaultIsolation = "Hyper-V" - } - } - elseif ($hostOsVersion.Major -eq $bestContainerOsVersion.Major -and $hostOsVersion.Minor -eq $bestContainerOsVersion.Minor -and $hostOsVersion.Build -eq $bestContainerOsVersion.Build) { - $defaultIsolation = "Process" - } - else { - $defaultIsolation = "Hyper-V" - } - } - catch { - $bestContainerOsVersion = [System.Version]"0.0.0.0" - $bestContainerOS = "Unable to determine the image which matches your OS best" - $defaultIsolation = "Hyper-V" - } - - $description = "Containers can run in process isolation or hyperv isolation, see more here: https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/hyperv-container`nIf not specified, the ContainerHelper will try to detect which isolation mode will work for your OS.`nIf an image with a matching OS is found, Process isolation will be favoured, else Hyper-V will be selected.`n`nYour host OS is Windows $($hostOSVersion.ToString())`n$bestContainerOS`n" - - if ($isAdministrator) { - $hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online - if ($hyperv) { - $description += "Hyper-V is enabled" - } - else { - $description += "Hyper-V is NOT enabled (you will not be able to use Hyper-V isolation on this host)" - $defaultIsolation = "Process" - } - } - $options = [ordered]@{"default" = "Allow the ContainerHelper to decide which isolation mode to use (on this host, this will be $defaultIsolation isolation)"; "process" = "Force Process isolation"; "hyperv" = "Force Hyper-V isolation" } + $description = "Containers can run in process isolation or hyperv isolation, see more here: https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/hyperv-container`nIf not specified, the ContainerHelper will try to detect which isolation mode will work for your OS.`nIf your host OS is updated and a matching container OS is found, Process isolation will be favoured, else Hyper-V will be selected." + $options = [ordered]@{"default" = "Allow the ContainerHelper to decide which isolation mode to use"; "process" = "Force Process isolation"; "hyperv" = "Force Hyper-V isolation" } $isolation = Select-Value ` -title @' @@ -1270,27 +1232,24 @@ $Step.Memory { if ($newBaseApp) { $description += "- $($newBaseApp)G for base app development`n" } - if ($isolation -eq "process" -or ($isolation -eq "default" -and $defaultIsolation -eq "Process")) { - $description += "`nWhen running Process isolation, the container will only use the actual amount of memory used by the processes running in the container from the host.`nMemory no longer needed by the processes in the container are given back to the host`nYou can set a limit to the amount of memory, the container is allowed to use." - $defaultDescription = "blank means no limit" - } - else { - $description += "`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container.`n" - if ($hostOsVersion.Build -ge 17763) { - $description += "Windows Server 2019 / Windows 10 1809 and later Windows versions are doing this by reserving the memory in the paging file and only using physical memory when needed.`nMemory no longer needed will be freed from physical memory again.`n" - try { - $CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2' - if ($CompSysResults.AutomaticManagedPagefile) { - $description += "Your paging file settings indicate that your paging file is automatically managed, you could consider changing this if you get problems with the size of the paging file.`n" - } + $description += "`n`nWhen running Process isolation, the container will only use the actual amount of memory used by the processes running in the container from the host. Memory no longer needed by the processes in the container are given back to the host. You can set a limit to the amount of memory, the container is allowed to use. " + $description += "(blank means no limit)" + + $description += "`n`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container. " + if ($hostOsVersion.Build -ge 17763) { + $description += "Windows Server 2019 / Windows 10 1809 and later Windows versions are doing this by reserving the memory in the paging file and only using physical memory when needed. Memory no longer needed will be freed from physical memory again. " + try { + $CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2' + if ($CompSysResults.AutomaticManagedPagefile) { + $description += "Your paging file settings indicate that your paging file is automatically managed, you could consider changing this if you get problems with the size of the paging file. " } - catch {} } - else { - $description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool.`n" - } - $defaultDescription = "blank will use ContainerHelper default which is 4G" + catch {} + } + else { + $description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool. " } + $description += "(blank will use ContainerHelper default which is 4G)" $memoryLimit = Enter-Value ` -title @' @@ -1304,7 +1263,7 @@ $Step.Memory { |___/ '@ ` -description $description ` - -question "Specify the amount of memory the container is allowed to use? ($defaultDescription)" ` + -question "Specify the amount of memory the container is allowed to use?" ` -default 'blank' ` -previousStep if ($script:wizardStep -eq $script:thisStep+1) { @@ -1315,7 +1274,7 @@ $Step.Memory { $memoryLimit = "" } else { - $memoryLimit = "$($memoryLimit.Trim().ToLowerInvariant().TrimEnd('gb').TrimEnd('g'))G" + $memoryLimit = "$($memoryLimit.ToLowerInvariant().Trim(' gb'))G" } } } diff --git a/HelperFunctions.ps1 b/HelperFunctions.ps1 index c386a9f5e..4a6aa7648 100644 --- a/HelperFunctions.ps1 +++ b/HelperFunctions.ps1 @@ -552,7 +552,7 @@ function CopyAppFilesToFolder { New-Item -Path $folder -ItemType Directory | Out-Null } $appFiles | Where-Object { $_ } | ForEach-Object { - $appFile = $_ + $appFile = "$_" if ($appFile -like "http://*" -or $appFile -like "https://*") { $appUrl = $appFile $appFileFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) @@ -564,13 +564,8 @@ function CopyAppFilesToFolder { } } elseif (Test-Path $appFile -PathType Container) { - get-childitem $appFile -Filter '*.app' -Recurse | ForEach-Object { - $destFile = Join-Path $folder $_.Name - if (Test-Path $destFile) { - Write-Host -ForegroundColor Yellow "::WARNING::$([System.IO.Path]::GetFileName($destFile)) already exists, it looks like you have multiple app files with the same name. App filenames must be unique." - } - Copy-Item -Path $_.FullName -Destination $destFile -Force - $destFile + Get-ChildItem $appFile -Recurse | ForEach-Object { + CopyAppFilesToFolder -appFile $_.FullName -folder $folder } } elseif (Test-Path $appFile -PathType Leaf) { @@ -587,9 +582,7 @@ function CopyAppFilesToFolder { $copied = $true } Expand-Archive $appfile -DestinationPath $tmpFolder -Force - Get-ChildItem -Path $tmpFolder -Recurse | Where-Object { $_.Name -like "*.app" -or $_.Name -like "*.zip" } | ForEach-Object { - CopyAppFilesToFolder -appFile $_.FullName -folder $folder - } + CopyAppFilesToFolder -appFiles $tmpFolder -folder $folder } finally { Remove-Item -Path $tmpFolder -Recurse -Force diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index ef510cd0d..3ed402196 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,4 +1,9 @@ 6.0.12 +Issue 3432 New-BcContainerWizard stopped working after generic images with ltsc2016, ltsc2019 and ltsc2022 was introduced +Make parameters in Copy-AppFilesToFolder mandatory +Support .zip files in folders in Copy-AppFilesToFolder +Issue 3431 Run-TestsInBcContainer, Get-TestsFromBcContainer and Run-ConnectionTest doesn't work if container is using SSL +Issue 3427 New-BCContainer in version 6.0.11 failed to run completely 6.0.11 Issue 3420 New-BcImage uses hyperv even if it is disabled