Mas*_*aus 1 visual-studio-code vscode-tasks
我正在同时尝试许多小项目,并在根文件夹上打开一个 VS Code 窗口。
它们可以是 JS 项目或 Python 项目,或其他可通过终端命令运行的项目。
我想创建一个 VS Code任务:
1) 在当前打开并聚焦的文件上启动程序;
2) 将当前工作目录设置为该文件的目录。
这必须动态发生,即我不想每次想要启动不同的文件时都手动设置当前文件和当前工作目录。
我怎样才能做到这一点?
您可以在文件中使用变量${fileDirname}和。${file}tasks.json
假设您正在尝试使用 Python。
这里有两个解决方案:
"tasks": [
{
"label": "start",
"type": "shell",
"command": "python3 ${file}",
"options": {
"cwd": "${fileDirname}"
}
"problemMatcher": []
}
]
Run Code Online (Sandbox Code Playgroud)
或者
"tasks": [
{
"label": "start",
"type": "shell",
"command": "cd ${fileDirname} && python3 ${file}",
"problemMatcher": []
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1970 次 |
| 最近记录: |