如何配置任务以在vscode中调用powershell脚本

Joh*_*aze 6 visual-studio-code

我试图在visual studio代码中设置一个构建任务来调用用PowerShell编写的现有构建脚本.这是我如何设置我的构建任务

{
    "version": "0.1.0",
    "command": "powershell",
    "isShellCommand": true,
    "args": [   
        "-File ${cwd}/source/deployment/build.ps1",
        "-NoProfile",
        "-ExecutionPolicy Unrestricted"
    ],
    "taskSelector": "-task ",
    "showOutput": "always",
    "tasks": [
        {
            "taskName": "build",
            "showOutput": "always",
            "isBuildCommand": true
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

但这里是我运行任务时的输出

.:无法加载文件C:\ Users\chkeita\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因为在此系统上禁用了运行脚本.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=135170上的 about_Execution_Policies .在行:1个字符:3 +.'C:\ Users\chkeita\Documents\WindowsPowerShell\Microsoft.PowerShell_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:SecurityError:(:) [],PSSecurityException + FullyQualifiedErrorId :UnauthorizedAccess -File:术语"-File"未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试.在行:1 char:1 + -File f:\ Dev\spf3/source/deployment/build.ps1 -NoProfile -executionpo ... + ~~~~~ + CategoryInfo:ObjectNotFound:( - File:String)[] ,CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

我尝试重新排序参数并将它们合并在一个字符串中但没有任何成功

我错过了什么?有没有更好的方法在vscode中执行此操作

Joh*_*aze 9

这是工作版.有关详细信息,请参阅github 讨论

{
    "version": "0.1.0",
    "command": "powershell",
    "args": [   
        "-ExecutionPolicy",
        "Unrestricted",
        "-NoProfile",
        "-File",
        "${cwd}/source/deployment/build.ps1"       
    ],
    "taskSelector": "-task ",
    "showOutput": "always",
    "tasks": [
        {
            "taskName": "build",
            "showOutput": "always",
            "isBuildCommand": true
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)