【发布时间】:2018-10-23 16:15:14
【问题描述】:
我尝试为将在我的 Windows 子系统 Linux 中运行的 Visual Studio Code 任务设置环境变量。但是,它似乎不起作用。这是我的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.
请注意,默认情况下,shell 已手动修改为 C:\WINDOWS\SysNative\bash.exefor WSL,推荐使用 here 和 here。
【问题讨论】:
-
见environment variable not found在你的情况下你需要使用
$env:test -
@Mark 谢谢!我更改为 ${env:test} 仍然无法正常工作。似乎根本没有设置环境变量。
-
@YuxiangWang 答案是here。您根本无法在 tasks.json 任务定义的
args或command中引用以这种方式设置的环境变量。
标签: visual-studio-code vscode-settings windows-subsystem-for-linux vscode-tasks