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

11
以这种方式,它不在子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"]
    }
]

1
你的问题不够清晰。你想要做什么? - Kirill Pashkov
看一下我的答案,我认为它会解决你的问题。 - Alberto S.
3个回答

9

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

在你的情况下,假设你有一些PowerShell脚本./scripts/mycustomPSscript.ps1,你想将其作为一个 vscode任务 运行。为了达成这个目标,请编辑任务文件,使其遵循以下示例:

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

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终端,输出确实会显示在其中。

1
这不是一个任务,问题是关于创建任务的。 - metablaster

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接