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

3
  • Try changing: "-ExecutionPolicy Unrestricted" to "Set-ExecutionPolicy -ExecutionPolicy Unrestricted" Commented Feb 26, 2016 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. Commented Feb 26, 2016 at 14:24
  • it doesn't help, these are the paramter the powershell command (technet.microsoft.com/en-us/library/hh847736.aspx) and i tested it in a command line and it works Commented Feb 26, 2016 at 18:33

1 Answer 1

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
        }
    ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.