Al: "preLaunchTask" is not working in launch.json

Created on 9 Sep 2019  Â·  12Comments  Â·  Source: microsoft/AL

Describe the bug
"preLaunchTask" is not run before the before the debug session starts

To Reproduce
Steps and to reproduce the behavior:

  1. Create a new task:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "My Task",
            "type": "shell",
            "command": "echo Hello",
            "problemMatcher": []
        }
    ]
}
  1. Add the created task to the launch.json:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "al",
            "request": "launch",
            "name": "Dev",
            "server": "https://MyBCServer",
            "schemaUpdateMode": "ForceSync",
            "serverInstance": "NAV",
            "authentication": "UserPassword",
            "startupObjectId": 77950,
            "startupObjectType": "Page",
            "breakOnError": true,
            "launchBrowser": true,
            "preLaunchTask": "My Task"
        }
    ]
}
  1. Start the debugging session with F5

Expected behavior
The task should be run before the debug session starts

Screenshots
Log output:

[2019-09-09 09:06:01.93] Publishing AL application using launch configuration 'Dev'.
[2019-09-09 09:06:02.00] Targeting server 'https://MyBCServer' and server instance 'NAV'.
[2019-09-09 09:06:02.01] Using user name and password authentication. User name used is: 'APT'.
[2019-09-09 09:06:02.03] Sending request to https://MyBCServer:7049/NAV/dev/apps?SchemaUpdateMode=forcesync
[2019-09-09 09:06:02.83] Success: The package 'anaptis GmbH_Test_1.0.0.0.app' has been published to the server.

Versions:

  • AL Language: 3.0.168874
  • Business Central: Platform 14.0.35570.0 + Application 35602 (DE Business Central 14.4)
investigate vscode-integration

Most helpful comment

Support for this is absolutly needed, why having this awesome tool (vscode) and then not be able to use the cool features it provides for any other language...

That said since i now have used tasks quite a bit, i tried if it would be possible to workaround the issue by using tasks as the starting point instead of the launch.json config.
I came up with this chained tasks configuraiton which allow you to use a task (or as many as you like) before exetuing the al.publish command.
This is a somewhat hidden feature that is using commands as inputs in tasks:
https://code.visualstudio.com/docs/editor/variables-reference#_input-variables

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prebuild",
            "command": "powershell.exe",
            "args": [
                "-NoProfile",
                "-ExecutionPolicy",
                "Bypass",
                "Write-Host 'Pre Build...';sleep 3;Write-Host 'Finished!'"                
            ],           
            "problemMatcher": [],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "panel": "dedicated",
                "showReuseMessage": false,
                "clear": true
            }
        },
        {
            "label": "deploy",
            "type": "shell",
            "command": "${input:albuildanddeploy}",
            "problemMatcher": [],
            "dependsOn": [
                "prebuild"
            ]            
        }
    ],
    "inputs": [
        {
          "id": "albuildanddeploy",
          "type": "command",
          "command": "al.publish",
        }
      ]
}

Then you could map the "deploy" task to a shortcut (Replace F5 if you like) and you should have the same Result as with a regular preLaunchTask.`

keybindings.json

[
    {
        "key": "f5",
        "command": "-al.publish",
        "when": "alExtensionActive && !inDebugMode"
    },
    {
        "key": "f5",
        "command": "workbench.action.tasks.runTask",
        "args": "deploy",
        "when": "alExtensionActive && !inDebugMode"
    }
]

All 12 comments

I confirm this. I'm not able to start a task with "preLaunchTask" in launch.json with AL too. Works on other languages.

The problem still exists in the September release (version 1.39) of VS Code and AL Language extension version 4.0.182565.

I also tried the "postDebugTask" with the same effect

I was able to start the "preLaunchTask" with a click on the green arrow in the debug window

Green Arrow In Debug Window

The downside of this workaround is that the app is no longer being build.

I think that the reason that this workaround is working is because it uses VS Codes own Debugging mode. As you can see in the following screenshot pressing F5 while the AL Extension is active the "AL: Publish with debugging" command is being run and not the "Debug: Start Debugging" command.

Bound keys to F5

Hi @Sven-Niehus,
Have you tried adding a prelaunch task for the command AL:Package?

Hi @thpeder,

Can you elaborate?

I added the preLaunchTask in the launch.json (as you can see in my first post first post in this thread).

Or are you talking about adding the AL: Package command to my task? I don't know how I could add a command from VS Code to my task.json. The documentation for the tasks.json file also doesn't state the possibility of doing this.

I haven't used this feature myself I just thought that there were a way to call a command defined in VSCode, but I can't find it either.

The problem still exists in the October release (version 1.40) of VS Code and AL Language extension version 4.0.198162.

Right now preLaunchTask is not supported in AL.
Great idea! Go ahead and post this to our Ideas forum at https://aka.ms/BusinessCentralideas, or vote up the idea if its already there. We're constantly monitoring top Ideas and will consider them for a future release.

I don't think that you understand the issue.
The AL extension is breaking the default behavior of VS Code and thus this is a bug in the extension that needs to be fixed.
It is not a feature request. It's a bug fixing request for the bug that is being introduced by the AL Extension

Support for this is absolutly needed, why having this awesome tool (vscode) and then not be able to use the cool features it provides for any other language...

That said since i now have used tasks quite a bit, i tried if it would be possible to workaround the issue by using tasks as the starting point instead of the launch.json config.
I came up with this chained tasks configuraiton which allow you to use a task (or as many as you like) before exetuing the al.publish command.
This is a somewhat hidden feature that is using commands as inputs in tasks:
https://code.visualstudio.com/docs/editor/variables-reference#_input-variables

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prebuild",
            "command": "powershell.exe",
            "args": [
                "-NoProfile",
                "-ExecutionPolicy",
                "Bypass",
                "Write-Host 'Pre Build...';sleep 3;Write-Host 'Finished!'"                
            ],           
            "problemMatcher": [],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "panel": "dedicated",
                "showReuseMessage": false,
                "clear": true
            }
        },
        {
            "label": "deploy",
            "type": "shell",
            "command": "${input:albuildanddeploy}",
            "problemMatcher": [],
            "dependsOn": [
                "prebuild"
            ]            
        }
    ],
    "inputs": [
        {
          "id": "albuildanddeploy",
          "type": "command",
          "command": "al.publish",
        }
      ]
}

Then you could map the "deploy" task to a shortcut (Replace F5 if you like) and you should have the same Result as with a regular preLaunchTask.`

keybindings.json

[
    {
        "key": "f5",
        "command": "-al.publish",
        "when": "alExtensionActive && !inDebugMode"
    },
    {
        "key": "f5",
        "command": "workbench.action.tasks.runTask",
        "args": "deploy",
        "when": "alExtensionActive && !inDebugMode"
    }
]

This isn't working in c++. I have include my code and my launch and task.json in my github hub repo https://github.com/pjuangph/ReadSTL/tree/main

The code compiles and runs fine when I use g++ main.cpp ReadSTL.cpp

This repository is for the AL language that is used to customize Microsoft Dynamics 365 Business Central and not for all problems regarding Visual Studio Code. @pjuangph

Was this page helpful?
0 / 5 - 0 ratings

Related issues

malue19 picture malue19  Â·  3Comments

daansaveyn picture daansaveyn  Â·  3Comments

RonKoppelaar picture RonKoppelaar  Â·  3Comments

kine picture kine  Â·  3Comments

worldofthenavcraft picture worldofthenavcraft  Â·  3Comments