Using the Invoke-Build module by Roman Kuzmin.
Inspired by build scripts I found on the web (but don't remember anymore)
This can be used as alternative to PSake + PSDepend.
There are several options to launch the build process:
- Running the build script
.\Testlab.build.ps1
- Executing
Invoke-Build
- Ctrl + Shift + B
- Using VSCode's built-in tasks (Press F1, then type
> Tasks: Run Task
) - F5 Debugging
If you do not have the Invoke-Build module installed, the build script ensures it's availability by downloading the module from PSGallery. This process is called "bootstrapping".
Call Invoke-Build ?
This will show you somehing like:
Name Jobs Synopsis
---- ---- --------
-Hello {} Hello World
Clean {} Deletes the Dependencies folder
Restore {Clean, {}} Downloads required modules to build the project
Import {} Imports the Modules from the Dependencies folder
Close-Module-Versions {Import, {}} Tells the 'Restore' task to stick to the modules current versions
Open-Module-Versions {} Allows the 'Restore' task to load the latest version of the modules
Install-VSCode-build-helpers {} Installs task-completion and F5 debugging experience with VSCode
.
When launching the build with Invoke-Build
or by using the VSCode commands the default task is executed (which in our case is doing nothing as this is just for testing).
Nevertheless if you run Testlab.build.ps1 without specifying a task, the tasks "Restore" and "Import" are executed before the default task. This supports a smooth first run experience in which the whole system is reset to a clean initial state when the script is run without parameters.
Downloading the dependencies alone does not yet make sure they are loaded regardless of whether the same modules are already installed on the machine (but probably with another version). To make sure the modules are loaded preferably from the dependencies folder during development time we must add it to the PSModulePath.
$ProjectRoot = Resolve-Path . | Select-Object -ExpandProperty Path
Add-PathVariable "$ProjectRoot\.dependencies" -Name "PSModulePath" -Prepend
To integrate the tasks into VSCode's built-in task system, execute the build task Install-VSCode-build-helpers.
Invoke-Build Install-VSCode-build-helpers
Consider using the alias ib
for Invoke-Build
in order to reduce typing even more. Namely, in your Microsoft.VSCode_profile.ps1 set
Set-Alias ib Invoke-Build