|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +title: VS Code Extension |
| 4 | +description: Install and configure the psake VS Code extension for task discovery, CodeLens, and build automation directly in your editor. |
| 5 | +--- |
| 6 | + |
| 7 | +# VS Code Extension |
| 8 | + |
| 9 | +The [psake VS Code extension](https://github.com/psake/psake-vscode) integrates psake's build system directly into Visual Studio Code. It automatically discovers your tasks, provides a dedicated explorer panel, and lets you run builds without leaving the editor. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- [Visual Studio Code](https://code.visualstudio.com/) v1.90 or later |
| 14 | +- [PowerShell extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell) for VS Code |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install the extension from the [VS Code Marketplace](https://marketplace.visualstudio.com/publishers/psake), or search for **psake** in the Extensions panel (`Ctrl+Shift+X`). |
| 19 | + |
| 20 | +The extension activates automatically when your workspace contains a `psakefile.ps1`, `psake.ps1`, or `build.ps1`. |
| 21 | + |
| 22 | +## Features |
| 23 | + |
| 24 | +### Task Provider |
| 25 | + |
| 26 | +The extension scans your `psakefile.ps1` and registers all tasks with VS Code's task system. Your default task is mapped to the Build group, so pressing `Ctrl+Shift+B` runs it immediately. |
| 27 | + |
| 28 | +Tasks refresh automatically when you save your build file. |
| 29 | + |
| 30 | +You can also reference psake tasks in `.vscode/tasks.json`: |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "version": "2.0.0", |
| 35 | + "tasks": [ |
| 36 | + { |
| 37 | + "type": "psake", |
| 38 | + "task": "Build" |
| 39 | + } |
| 40 | + ] |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### psake Tasks Explorer |
| 45 | + |
| 46 | +A sidebar panel in the Explorer view lists all discovered tasks with their descriptions and dependencies. From here you can: |
| 47 | + |
| 48 | +- **Run** any task with a single click |
| 49 | +- **Navigate** to a task's definition in your build file |
| 50 | +- **View** task dependencies at a glance |
| 51 | + |
| 52 | +### CodeLens |
| 53 | + |
| 54 | +Each `Task` declaration in your build file displays a **Run Task** action inline. Click it to execute the task directly from the editor. |
| 55 | + |
| 56 | +To disable CodeLens, set `psake.codeLens.enabled` to `false`. |
| 57 | + |
| 58 | +### Build Script Detection |
| 59 | + |
| 60 | +If your project includes a wrapper script such as `build.ps1`, the extension routes execution through it automatically. This ensures bootstrapping, dependency installation, and other setup steps run correctly. |
| 61 | + |
| 62 | +Set `psake.buildScript` to `"none"` to disable wrapper detection and call `Invoke-psake` directly. |
| 63 | + |
| 64 | +### Task Sync & IntelliSense |
| 65 | + |
| 66 | +- **Sync command**: Run `psake: Sync Tasks to tasks.json` to add all discovered tasks to your workspace configuration while preserving existing customizations. |
| 67 | +- **IntelliSense**: The `"task"` property in `.vscode/tasks.json` provides autocomplete for psake task names when using the `psake` type. |
| 68 | + |
| 69 | +### Snippets |
| 70 | + |
| 71 | +Nine built-in snippets help you scaffold build files quickly: |
| 72 | + |
| 73 | +| Prefix | Description | |
| 74 | +|---|---| |
| 75 | +| `psakeTask` | Basic task definition | |
| 76 | +| `psakeTaskFull` | Task with all options | |
| 77 | +| `psakeTaskDependsOnly` | Task that only declares dependencies | |
| 78 | +| `psakeProperties` | Properties block | |
| 79 | +| `psakeInclude` | Include statement | |
| 80 | +| `psakeFramework` | Framework block | |
| 81 | +| `psakeFormatTaskName` | FormatTaskName block | |
| 82 | +| `psakeTaskSetup` | TaskSetup block | |
| 83 | +| `psakeTaskTearDown` | TaskTearDown block | |
| 84 | + |
| 85 | +### Scaffold Command |
| 86 | + |
| 87 | +Run `psake: Install sample build file` to generate a starter `psakefile.ps1` with example tasks in your workspace. |
| 88 | + |
| 89 | +## Configuration |
| 90 | + |
| 91 | +All settings are under the `psake` namespace and update dynamically without restarting VS Code. |
| 92 | + |
| 93 | +| Setting | Default | Description | |
| 94 | +|---|---|---| |
| 95 | +| `psake.buildFile` | `psakefile.ps1` | Default build file name | |
| 96 | +| `psake.taskProvider.enabled` | `true` | Enable automatic task detection | |
| 97 | +| `psake.codeLens.enabled` | `true` | Show Run Task CodeLens above task declarations | |
| 98 | +| `psake.buildScript` | `""` (auto-detect) | Path to wrapper build script, or `"none"` to disable | |
| 99 | +| `psake.buildScriptTaskParameter` | `Task` | Parameter name the build script uses for task selection | |
| 100 | +| `psake.buildScriptParameters` | `""` | Additional parameters passed to the build script | |
| 101 | +| `psake.invokeParameters` | `""` | Additional parameters passed to `Invoke-psake` | |
| 102 | +| `psake.powershellExecutable` | `""` (auto-detect) | Path to PowerShell executable | |
| 103 | +| `psake.shellArgs` | `["-NoProfile"]` | Arguments passed to the PowerShell executable | |
| 104 | + |
| 105 | +## Troubleshooting |
| 106 | + |
| 107 | +**Tasks not appearing?** |
| 108 | +- Verify your build file is named `psakefile.ps1` (or matches your `psake.buildFile` setting) |
| 109 | +- Check that `psake.taskProvider.enabled` is `true` |
| 110 | +- Run `psake: Refresh Tasks` from the Command Palette |
| 111 | + |
| 112 | +**Build script not detected?** |
| 113 | +- The extension looks for `build.ps1` in the workspace root by default |
| 114 | +- Set `psake.buildScript` explicitly if your wrapper has a different name or location |
| 115 | + |
| 116 | +**Using a non-standard PowerShell?** |
| 117 | +- Set `psake.powershellExecutable` to the full path of your PowerShell binary |
| 118 | + |
| 119 | +## Further Reading |
| 120 | + |
| 121 | +- [psake VS Code extension on GitHub](https://github.com/psake/psake-vscode) |
| 122 | +- [Debugging psake in VS Code](../troubleshooting/debugging-guide.md) |
| 123 | +- [psake Agent Skill for AI-assisted builds](/blog/introducing-psake-agent-skill) |
0 commit comments