我试图在我的 tasks.json
中的任务中使用环境变量vscode
中的 C# 项目文件.
在我的 launch.json
文件我有这个代码来解析一个 .env 文件:
"configurations": [
{
...
"envFile": "${workspaceFolder}/.env",
}
]
然后我在
tasks.json
归档此任务:{
"label": "login",
"command": "sh",
"type": "shell",
"args": [
"${workspaceFolder}/etc/login.sh",
"${env:USERNAME}",
"${env:PASSWORD}"
]
}
这似乎是从 https://code.visualstudio.com/docs/editor/tasks 隐含的代码,但是(通过在另一个任务中通过回显进行测试)我发现了最后两个
args
为空白。上网查了一下,我想我找到了原因,configurations..env
由 tasks
使用自己,而不是被 task.json
访问运行,因此无法访问。我如何创建(使用)这些
env variables
内tasks.json
?
最佳答案
结帐 https://code.visualstudio.com/docs/editor/tasks-appendix
/**
* The environment of the executed program or shell. If omitted
* the parent process' environment is used.
*/
env?: { [key: string]: string };
例子{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "diagnostic",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/beam",
"env": {
"FOO": "baz",
}
},
"command": "printenv",
"problemMatcher": []
}
]
}
我不知道从文件中提取这些文件,例如 launch.json我会在 vscode repo 上打开一个问题
关于c# - 如何在 vscode 中访问 tasks.json 中的 .env 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58009115/