我如何配置任务以在 vscode 中调用 powershell 脚本 [英] How do i configure a task to call a powershell script in vscode

查看:43
本文介绍了我如何配置任务以在 vscode 中调用 powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio 代码中设置构建任务,以调用用 powershell 编写的现有构建脚本.这是我设置构建任务的方法

I am trying to set up a build task in visual studio code to call an existing build script written in powershell. Here is how i set up my build task

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

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

but here the output when i run the task

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

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

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

I have tried reordering the arguments and merging them in one string without any success

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

What am i missing? Is there a better way to do this in vscode

推荐答案

这里是工作版本.请参阅 github 讨论了解更多详情

here is working version. see the github discussion for more details

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

这篇关于我如何配置任务以在 vscode 中调用 powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆