我使用的是 Windows 10,vscode 中的默认 shell 是 git bash,所有任务都使用它。
对于特定任务,我想使用powershell。这可能吗
{
"label": "sometask",
"type": "shell",
"command": "sam build",
"group": "test"
}
对于以下工作。
https://code.visualstudio.com/docs/editor/tasks#_common-questions
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/d", "/c"
]
}
}
},
...
接受的答案是使用cmd,它没有解释它应该放在哪里,这适用于PowerShell:
在 .vscode/tasks.json 中
{
"version": "2.0.0",
"tasks": [
...,
{
"label": "Name",
"type": "shell",
"command": "Some Command",
"options": {
"shell": {
"executable": "powershell.exe"
}
}
}
]
}
如何配置 VSCode 任务以在集成终端中运行 PowerShell 脚本
在集成终端 Visual Studio Code 上运行代码
功能为了使用此应用程序,请创建一个配置文件 在你的 .vscode 目录中。该文件将定义可用的任务。
例如,它可能看起来像:
{
"Task Name": {
"cmd": "ps", // The command you'd like to run in the terminal
"args": ["-a"], // Array of string arguments to the command
"stealFocus": true, // If this is true, focus will jump to the terminal right away
"shellOptions": {} // This allows you to override the default shell options described below for this specific task.
},
"Task 2:" {
"cmd": { // cmd and args can also vary based on platform, just like default shell.
"default": "vi",
"mac": "nano",
"linux": "emacs"
},
"args": {
"default": []
"mac": ["-B"]
}
}
}