在 vscode for WSL 中的 task.json 中设置环境变量 [英] Set environment variables in task.json in vscode for WSL

查看:119
本文介绍了在 vscode for WSL 中的 task.json 中设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to set environment variables for my Visual Studio Code tasks that will run in my Windows Subsystem Linux. However, it does not seem to work. Here is my tasks.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 的 shell 已手动修改为 C:\WINDOWS\SysNative\bash.exe,如推荐的 此处这里.

Note that by default shell has been manually modified to C:\WINDOWS\SysNative\bash.exefor WSL, as recommended here and here.

推荐答案

选项对象在任何任务之外,所以:

The options object goes outside of any task, so:

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

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

And then access the options argsuments like so:

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

这篇关于在 vscode for WSL 中的 task.json 中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆