0

We have a slew of folks doing development through the same GitLab repo. We are using VS Code tasks to execute internal commands. The main command is the same for everyone: internal_command on Windows and internalCommand on Linux.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label" : "do it",
            "type" : "shell",
            "windows": {
                "command": "internal_command"
            },
            "linux": {
                "command": "internalCommand"
            }
        }
    ]
}

This works as expected.

Some users need/want to run a specific command before the main command. For example, one use wants to rename a file, another user wants to change an environment variable, etc...

We don't want to have multiple versions of .vscode/tasks.json cause that is a mess when pushing things to GitLab.

So I am wondering if there is a way to specify user specific tasks in the project's .vscode/tasks.json file?

1 Answer 1

1

You can with the help of the extension Command Variable it allows you to use the content of a file as a command in the terminal. The file can also contain Key-Value pairs or be a JSON file.

Say you store this userTask.txt or userTask.json file in the .vscode folder and add the file to the .gitignore file.

With the current version of the extension the file userTask.txt has to exist, I will add an option to supply alternative text in case the file does not exist. You can fill the file with a dummy command like echo No User Task

Set up your task.json like

{
  "version": "2.0.0",
  "tasks": [
    {
      "label" : "do it",
      "type" : "shell",
      "windows": {
        "command": "internal_command"
      },
      "linux": {
        "command": "internalCommand"
      },
      "dependsOrder": "sequence",
      "dependsOn": ["userTask"]
    },
    {
      "label" : "userTask",
      "type" : "shell",
      "command": "${input:getUserTask}"
    }
  ],
  "inputs": [
    {
      "id": "getUserTask",
      "type": "command",
      "command": "extension.commandvariable.file.content",
      "args": {
        "fileName": "${workspaceFolder}/.vscode/userTask.txt"
      }
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.