Last couple of days, I got a number of questions from people that all came down to the same issue: how to set the correct settings in the launch.json so Visual Studio Code can connect to NAV 2018. In most cases I saw the same mistake being made. A logical mistake, but also one that leaves you probably wondering why it works that way.
Let’s assume you have enabled the development port in your NAV 2018. Look here to read how that is done.
When you create a new workspace in VS Code with the AL:Go! command, you get by default a launch.json that looks like this:
Basically the only thing you need to change is the servername. In my case that would be navserver. Some people also change the default developer port 7049 to another port number, let’s say 7149. A common mistake is to put that port number into the server url.
Let’s see what happens when we try to download the symbol files.
It uses port number 7049! How is that possible?
The port number in the server url is just ignored. Instead you should specify the port number with a separate setting. If that setting is missing, then the default port number 7049 is used. Let’s specify the port number and see what happens.
Let’s download the symbol files again, and watch the url.
Conclusion: do not specify a port number in the server url. Instead, use the port setting to specify the developer port number.
Another common mistake is that the server url and the web client url are assumed to be the same. That is not the case. The two settings we talked about above, the server url and the developer port number, are the only settings you need in the launch.json.
When VS Code publishes the extension to the NAV server, the NAV server returns the web client url as a response. This url is then opened in the browser. No setting needed in the launch.json at all.
The NAV server reads that setting from the Web Client Base Url server setting.
Let’s prove that with an example. In the next screenshot, I set the key to a different value. Sorry, it’s PowerShell, I only have NAV 2018 installed with docker images.
How to check the output? Well, I can of course show a browser screen with that url, but would that prove my point? So I figured that a Fiddler trace would probably more convincing. Here is the Fiddler trace when VS Code publishes the extensions to the server.
Look at the response, it contains the setting that I did with the PowerShell command.
And here is what happens when the Web Client Base Url is not set:
I hope this demystifies how VS Code and the NAV server work together!