Pre-build commands in NRF Connect with VS Code

Is there a way to add a pre-build command in NRF Connect for VS Code?

Parents
  • Hi, 

    I know this is an old post, but I was recently facing the same issue and I couldn't find a complete solution. So, I wanted to mention what I did to solve it in case someone else is fighting with this.

    Nordic provides the steps on how to create a custom binding task (link), but that was like 70% of what I needed to create a pre-build command. Once you create the binding for your program, the "nrf-connect.taskBindings" variable is added to the"settings.json" file. After this, you will have to create a "tasks.json" file under your ".vscode" folder. It should look like this picture.

    On the "tasks.json" file, you need to add 2 tasks. One task for the prebuild and another one for your build binding.

    For the prebuild task, you just need to add 2 variables, "label": "pre-build", and "command": "<PUT YOUR COMMAND HERE>"

    For the build binding, you can copy the structure provided by Nordic in the link to add the default structure. A quick trick is that if you press CTRL+SHIFT+P, then type "Tasks: Configure Task", and select which one you one, it will automatically create it for you. Then, you need to add 2 variables "group" and "dependsOn". They are going to link your build task with the prebuild task making sure the prebuild task is compiled before this task. I am adding an example below for extra details.

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "pre-build",
                "command": "echo PRE BUILD COMMAND"
            },
            {
                "label": "Build: HelloWorld/build (active)",
                "type": "nrf-connect-build",
                "config": "${workspaceFolder}\\build",
                "runCmake": false,
                "clean": false,
                "problemMatcher": [
                    "$cmake",
                    "$kconfig",
                    "$kconfig_syntax",
                    "$kconfig_syntax_files",
                    "$dts",
                    "$dts_syntax"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "dependsOn": [
                    "pre-build"
                ]
            }
        ]
    }

    I hope this helps someone since it took me some time to reach this solution.

Reply
  • Hi, 

    I know this is an old post, but I was recently facing the same issue and I couldn't find a complete solution. So, I wanted to mention what I did to solve it in case someone else is fighting with this.

    Nordic provides the steps on how to create a custom binding task (link), but that was like 70% of what I needed to create a pre-build command. Once you create the binding for your program, the "nrf-connect.taskBindings" variable is added to the"settings.json" file. After this, you will have to create a "tasks.json" file under your ".vscode" folder. It should look like this picture.

    On the "tasks.json" file, you need to add 2 tasks. One task for the prebuild and another one for your build binding.

    For the prebuild task, you just need to add 2 variables, "label": "pre-build", and "command": "<PUT YOUR COMMAND HERE>"

    For the build binding, you can copy the structure provided by Nordic in the link to add the default structure. A quick trick is that if you press CTRL+SHIFT+P, then type "Tasks: Configure Task", and select which one you one, it will automatically create it for you. Then, you need to add 2 variables "group" and "dependsOn". They are going to link your build task with the prebuild task making sure the prebuild task is compiled before this task. I am adding an example below for extra details.

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "pre-build",
                "command": "echo PRE BUILD COMMAND"
            },
            {
                "label": "Build: HelloWorld/build (active)",
                "type": "nrf-connect-build",
                "config": "${workspaceFolder}\\build",
                "runCmake": false,
                "clean": false,
                "problemMatcher": [
                    "$cmake",
                    "$kconfig",
                    "$kconfig_syntax",
                    "$kconfig_syntax_files",
                    "$dts",
                    "$dts_syntax"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "dependsOn": [
                    "pre-build"
                ]
            }
        ]
    }

    I hope this helps someone since it took me some time to reach this solution.

Children
No Data
Related