我尝试为在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 已经手动修改为 WSL 的
C:\WINDOWS\SysNative\bash.exe
,如这里和这里所推荐的那样。
$env:test
。 - Mark