【问题标题】:How to run a specific task in a powershell only in vscode如何仅在 vscode 中在 powershell 中运行特定任务
【发布时间】:2020-12-23 19:20:39
【问题描述】:

我在 Windows 10 上,我在 vscode 中的默认 shell 是 git bash,它被所有任务使用。

对于特定任务,我想使用 powershell。这可能吗

        {
            "label": "sometask",
            "type": "shell",
            "command": "sam build",
            "group": "test"
        }

【问题讨论】:

  • 那么为什么您发布的示例不包括 Powershell,如果这是您想要运行的?你必须告诉任务/json,使用什么。

标签: powershell visual-studio-code vssettings


【解决方案1】:

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

Run Code on integrated terminal Visual Studio Code

Integrated Terminal Tasks

功能 为了使用这个应用程序,创建一个配置文件 在您的 .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"]
        }
    }
}

How do I configure a task to call a PowerShell script

【讨论】:

  • 我得到这个错误 cmd option is not allowed at this place.
【解决方案2】:

对于以下工作。

https://code.visualstudio.com/docs/editor/tasks#_common-questions

{
"version": "2.0.0",
"windows": {
    "options": {
        "shell": {
            "executable": "cmd.exe",
            "args": [
                "/d", "/c"
            ]
        }
    }
},
...

【讨论】:

    猜你喜欢
    • 2015-07-10
    • 2017-09-04
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多