microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
383 stars 247 forks source link

Missing PowerShell Module “Microsoft.Dynamics.Nav.Apps.Tools” in Business Central 22 Container #3181

Closed FSharpCSharp closed 4 months ago

FSharpCSharp commented 1 year ago

Describe the issue When creating a Business Central 22 container, it appears that the PowerShell module “Microsoft.Dynamics.Nav.Apps.Tools” is missing after creation. This makes it impossible to use any of the CmdLets contained therein, such as Export-NAVAppTableData. The command always fails when executing the PowerShell command in the container because it cannot find it.

To reproduce the issue, I entered the container after creating it (see script below) using the command “Enter-BcContainer -containerName test-container” and tried to use the CmdLet Export-NAVAppTableData. Unfortunately, this fails with an error message and I currently do not know what else to do.

Can you please help me resolve this issue? Thank you.

Scripts used to create container and cause the issue

$securePassword = ConvertTo-SecureString -String "" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -argumentList "test", $securePassword

New-BcContainer -accept_eula `
                -accept_outdated `
                -assignPremiumPlan `
                -auth NavUserPassword `
                -containerName test-container `
                -doNotExportObjectsToText `
                -Credential $credential `
                -artifactUrl (Get-BCArtifactUrl -country de -version 22.0 -type OnPrem)

Full output of scripts

Default parameter shortcuts = CommonStartMenu
Default parameter UpdateHosts = True
Default parameter doNotCheckHealth = True
Default parameter MemoryLimit = 8g
BcContainerHelper is version 5.0.5
BcContainerHelper is running as administrator
HyperV is Disabled
UsePsSession is True
Host is Microsoft Windows Server 2016 Datacenter - 10.0.14393.6167
Docker Client Version is 20.10.23
Docker Server Version is 20.10.23
Removing Desktop shortcuts
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:10.0.14393.6085
Disabling Health Check (always report healthy)
Creating Container test-container
Style: onprem
Multitenant: No
Version: 22.0.54157.55195
Platform: 22.0.55180.0
Generic Tag: 1.0.2.14
Container OS Version: 10.0.14393.6085 (ltsc2016)
Host OS Version: 10.0.14393.6167 (ltsc2016)
WARNING: Host OS and Base Image Container OS doesn't match and HyperV is not installed. If you encounter issues, you could try to install HyperV.
Using process isolation
Using locale de-DE
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Files in C:\ProgramData\BcContainerHelper\Extensions\test-container\my:
- AdditionalOutput.ps1
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container test-container from image mcr.microsoft.com/businesscentral:10.0.14393.6085
72c2af140723e3b2e1f92be0779c271157a4630abcaab64633115c0842bcef4c
Waiting for container test-container to be ready
Using artifactUrl https://bcartifacts.azureedge.net/onprem/22.0.54157.55195/de
Using installer from C:\Run\210-new
Installing Business Central
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\onprem\22.0.54157.55195\platform\ServiceTier\Program Files
c:\dl\onprem\22.0.54157.55195\platform\ServiceTier\System64Folder
Copying PowerShell Scripts
c:\dl\onprem\22.0.54157.55195\platform\WindowsPowerShellScripts\Cloud\NAVAdministration
c:\dl\onprem\22.0.54157.55195\platform\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
c:\dl\onprem\22.0.54157.55195\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\onprem\22.0.54157.55195\platform
c:\dl\onprem\22.0.54157.55195\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\onprem\22.0.54157.55195\de\ConfigurationPackages
Copying Test Assemblies
C:\dl\onprem\22.0.54157.55195\platform\Test Assemblies
Copying Applications
C:\dl\onprem\22.0.54157.55195\de\Applications
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for CRONUS on localhost\SQLEXPRESS
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing license file
Stopping Business Central Service Tier
Installation took 197 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.30.96.1 in container hosts file
Starting Container
Hostname is test-container
PublicDnsName is test-container
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint A6C05CF8153D1B5128B363D6D40F21D67C2CE72C
DNS identity test-container
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: BC
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\BC
Create the application pool BC
Create website: NavWebApplicationContainer without SSL
Update configuration: navsettings.json
Done Configuring Web Client
Creating http download site
Setting SA Password and enabling SA
Creating test as SQL User and add to sysadmin
Creating SUPER user
WARNING: The password that you entered does not meet the minimum requirements. 
It should be at least 8 characters long and contain at least one uppercase 
letter, one lowercase letter, and one number.
Assign Premium plan for TEST
Container IP Address: 172.30.103.210
Container Hostname  : test-container
Container Dns Name  : test-container
Web Client          : http://test-container/BC/
Dev. Server         : http://test-container
Dev. ServerInstance : BC
Setting test-container to 172.30.103.210 in host hosts file

Files:
http://test-container:8080/ALLanguage.vsix

Container Total Physical Memory is 32.0Gb
Container Free Physical Memory is 6.4Gb

Initialization took 33 seconds
Ready for connections!
Reading CustomSettings.config from test-container
Creating Desktop Shortcuts for test-container
Cleanup old dotnet core assemblies
Container test-container successfully created

Use:
Get-BcContainerEventLog -containerName test-container to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName test-container to get debug information about the container
Enter-BcContainer -containerName test-container to open a PowerShell prompt inside the container
Remove-BcContainer -containerName test-container to remove the container again
docker logs test-container to retrieve information about URL's again
...

Scripts that cause the issue

Enter-BcContainer -containerName test-container
Export-NAVAppTableData

Full output of scripts

[TEST-CONTAINER]: PS C:\Run> Export-NAVAppTableData
The term 'Export-NAVAppTableData' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (Export-NAVAppTableData:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

freddydk commented 1 year ago

That DLL was moved into the management folder under the service folder (as the service folder was upgraded to dotnet core) You can still load it - but you need to do it manually.

Inside the container, you need to run:

import-module (Get-Item 'C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\microsoft.dynamics.nav.apps.tools.dll').FullName
FSharpCSharp commented 1 year ago

Thank you for your quick response, that indeed solves my problem. I have two questions:

  1. Would it be possible to load this DLL by default so that the PowerShell scripts could be used in any container, regardless of the version?
  2. Did Microsoft announce anywhere that the DLL was moved, because I couldn't find any hint or similar information about it?

Thank you for your help.

freddydk commented 1 year ago

It would require me to rebuild all generic images and would also incur some risk. And since this was changed 5 months ago and this is the first issue regarding that, my assumption is that it isn't much used. Having said that - you can download https://github.com/microsoft/nav-docker/blob/master/generic/Run/Prompt.ps1 and add a few lines after line 53 - and then specify the new prompt.ps1 in -myscripts - then you should have this.

FSharpCSharp commented 1 year ago

I hope this message finds you well. I was wondering if you could help me understand something. Previously, all loaded modules were available by default in the container and everything worked smoothly. However, it seems that the DLLs have been moved and I now have to adjust my processes for certain versions.

I understand that there may be an adjustment effort involved, but as a Product Owner, could you please provide some support for such use cases? It would be really helpful if the DLL is always present in the new directory from now on, so that it would work in all future containers. This would save us from having to constantly adjust our processes when creating containers.

I would be grateful if you could consider this request. Thank you for your time and support.

freddydk commented 1 year ago

Not sure how to respond. Business Central is a living thing and the change to dotnet core has many advantages on performance and other things. Unfortunately, that change also ment that we had to move the "old" dotnet 4.5 DLLs to another folder. Things like this will happen again - and this is one of the reasons we have created a tool like AL-Go for GitHub, to ensure that as few partners as possible will have to change their scripts themselves. The change happened 5 months ago - and this issue is the first issue with this - meaning that it is probably fair to say that it isn't frequently used.

If I am to modify the generic image to add this - I stand the risk of breaking things for the 1000s of other partners who have been working with 22 for the last 5 months.

At some point in time in the future, we might move the service tier to run on Linux and as such the generic image will change to Linux and you will have to modify scripts again - the entire model will then change.

People using AL-Go for GitHub will then just keep working. People who are maintaining their own scripts will have to adapt.

I will note it down, but a change is not coming for this in any near future.