我如何配置任务以调用vscode中的PowerShell脚本

问题描述:

我试图在Visual Studio代码中设置一个构建任务来调用PowerShell中编写的现有构建脚本。 这是我如何设置我的生成任务我如何配置任务以调用vscode中的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 
     } 
    ] 
} 

但这里的输出,当我运行

. : File C:\Users\chkeita\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170 . At line:1 char:3 + . 'C:\Users\chkeita\Documents\WindowsPowerShell\Microsoft.PowerShell_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess -File : The term '-File' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + -File f:\Dev\spf3/source/deployment/build.ps1 -NoProfile -executionpo ... + ~~~~~ + CategoryInfo : ObjectNotFound: (-File:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

我试图重新排序的参数和在一个字符串合并他们没有任何成功的任务

我错过了什么? 有没有更好的方法来做到这一点在vscode

+0

尝试改变:“-ExecutionPolicy无限制”到“设置ExecutionPolicy -ExecutionPolicy无限制” – seN

+0

它似乎这条道路将不得不改变: - 文件$ {CWD} \源\部署\ build.ps1;不知道“-File”是否是正确的命令tbh。 – seN

+0

它没有帮助,这些是参数powershell命令(https://technet.microsoft.com/en-us/library/hh847736.aspx) 和我测试它在命令行,它的工作原理 –

这里是工作版本。看到GitHub的discussion更多细节

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