在vscode中为WSL设置task.json中的环境变量

时间:2018-10-23 16:15:14

标签: visual-studio-code vscode-settings windows-subsystem-for-linux vscode-tasks

我试图为将在Windows子系统Linux中运行的Visual Studio Code任务设置环境变量。但是,它似乎不起作用。这是我的task.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "test env",
            "type": "shell",
            "command": "echo",
            "args": [
                "$test"
            ],
            "options": {
                "env": {
                    "test": "test_string"
                }
            }

        },
    ]
}

输出为:

> Executing task in folder ex12-test: echo $test <



Terminal will be reused by tasks, press any key to close it.

请注意,默认情况下,WSL已根据建议的herehere手动将shell修改为C:\WINDOWS\SysNative\bash.exe

1 个答案:

答案 0 :(得分:0)

options对象不在任何任务之外,所以:

format
  "version": "2.0.0",
  "options": {
      "env": {
        "test": "test_string"
      }
   }
   "tasks": [
    {
        "label": "test env",
        "type": "shell",
        "command": "echo",
        "args": [
            "$env:test"
        ],
    },

然后像这样访问选项参数:

$env:test  or    ${env:test}
]