如何配置 VSCode 任务以在集成终端中运行 powershell 脚本

Jas*_*ton 11 powershell task visual-studio-code vscode-tasks

以这样的方式,它不在子外壳中。我需要它能够准备环境...设置环境变量。

"version": "0.1.0",
"command": "${workspaceFolder}/Invoke-Task.ps1",
/*"command": "powershell",   creates subshell so doesn't work*/
"isShellCommand": false,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
    {
        "taskName": "task1",
        "args": ["task1"]
    },
    {
        "taskName": "task2",
        "args": ["task2"]
    }
]
Run Code Online (Sandbox Code Playgroud)

Alb*_*rto 10

抱歉,您没有正确编辑该.vscode/tasks.json文件。

在您的场景中,假设您有一些 powershell 脚本./scripts/mycustomPSscript.ps1想要作为vscode task. 对于这样的目标,编辑任务文件,使其遵循以下示例:

{
    "version": "2.0.0",
    "tasks": [  
        {
            "label": "Run-some-custom-script",
            "detail": "Prepare some ENV variables for the deployment",
            "type": "shell",
            "command": "./../scripts/mycustomPSscript.ps1",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)


pos*_*ote 1

如果我正确理解你的要求的话,自 2017 年以来这一直是可行的。

Integrated-terminal-tasks README 此扩展允许工作区定义应在 VSCode 交互式终端中运行的特定任务

https://marketplace.visualstudio.com/items?itemName=ntc.integrated-terminal-tasks

另外,您的帖子/查询可能被视为与此重复...

在集成终端 Visual Studio Code 上运行代码