7

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

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

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

Cheick
  • 2,154
  • 24
  • 28
  • Try changing: "-ExecutionPolicy Unrestricted" to "Set-ExecutionPolicy -ExecutionPolicy Unrestricted" – seN Feb 26 '16 at 14:17
  • And it seems that the path will have to change to: -File ${cwd}\source\deployment\build.ps1; not sure if "-File" is the correct command tbh. – seN Feb 26 '16 at 14:24
  • it doesn't help, these are the paramter the powershell command (https://technet.microsoft.com/en-us/library/hh847736.aspx) and i tested it in a command line and it works – Cheick Feb 26 '16 at 18:33

1 Answers1

12

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
        }
    ]
}
Cheick
  • 2,154
  • 24
  • 28
  • To spell it out: CLI parameters such as `-ExecutionPolicy` and `-NoProfile` must be placed _before_ a `-File` or (possibly implied) `-Command` argument in order to be effective. Otherwise they are considered arguments to the script file being invoked / part of the command to execute. – mklement0 May 30 '23 at 16:21