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

时间:2018-09-01 03:35:59

标签: powershell visual-studio-code task

以这种方式不在子shell中。我需要它能够准备环境...设置环境变量。

"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"]
    }
]

3 个答案:

答案 0 :(得分:0)

如果我正确地回答了您的问题,自2017年以来这是可行的。

  

integrated-terminal-tasks自述文件此扩展允许工作空间执行以下操作:   定义应在VSCode的交互式环境中运行的特定任务   终端

     

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

此外,您的帖子/查询也可能被视为此内容的重复...

  

Run Code on integrated terminal Visual Studio Code

答案 1 :(得分:0)

在launch.json文件中添加此配置对我来说很成功

 "version": "0.2.0",
"configurations": [
    {
        "type": "PowerShell",
        "request": "launch",
        "name": "PowerShell Launch Current File",
        "script": "put full path here\\launch.ps1",
        "args": ["${file}"],
        "cwd": "${file}"
    },...

不确定您所说的“集成终端”是什么意思,但是如果您要指的是输出确实会显示在VSC终端中。

答案 2 :(得分:0)

抱歉,您没有正确编辑.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
            }
        }
    ]
}
相关问题