How to configure a VSCode Task to run a powershell script in the integrated terminal

纵饮孤独 提交于 2021-01-28 10:40:44

问题


In such a way that it is not in a sub shell. I need it to be able to prepare the environment...set environment variable.

"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:


This has been doable since 2017, if I get your ask correctly.

integrated-terminal-tasks README This extension allows a workspace to define specific tasks that should be ran in VSCode's interactive terminal

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

Also, your post / query, could been seen as a duplicate of this...

Run Code on integrated terminal Visual Studio Code




回答2:


Adding this configuration in the launch.json file did the trick for me

 "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}"
    },...

Not sure what you mean by 'integrated terminal' but the output does show up in the VSC terminal if this is what you're referring to.




回答3:


I am sorry, but you are not correctly editing the .vscode/tasks.json file.

In your scenario, lets say you have some powershell script ./scripts/mycustomPSscript.ps1 you want to run as a vscode task. For such goal, edit the tasks file so it follows the below example:

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


来源:https://stackoverflow.com/questions/52124656/how-to-configure-a-vscode-task-to-run-a-powershell-script-in-the-integrated-term

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!