Skip to content

Build Scripts in Projects

Roman Kuzmin edited this page Mar 19, 2024 · 49 revisions

NOTE Consider naming build scripts like MyProject.build.ps1 instead of .build.ps1. The latter was historically used in some projects and was fine for Windows. But PowerShell 6.0+ is cross-platform and on Unix like systems "dot files" are treated as hidden by default.


Invoke-Build, Helps (PowerShell scripts)

These scripts are for pure PowerShell script projects. The following tasks are automated:

  • Clean the project directory
  • Run tests and compare results with expected
  • Build the help file (PowerShell MAML format)
  • Convert markdown files to HTML for packages
  • Create packages

SplitPipeline, Mdbc (C#, PowerShell modules)

These scripts are examples of mixed build tools: Invoke-Build and MSBuild work together and call each other. See how the configuration parameter is passed in both directions.

The task Build calls MSBuild in order to build the C# project:

exec { MSBuild Src\Mdbc.csproj /t:Build /p:Configuration=$Configuration }

The task PostBuild is called by MSBuild as the post-build event, it copies the just built module and its satellite files to one of the PowerShell module directories, so that it is ready to use/debug after the build. The post-build command line is:

PowerShell.exe -NoProfile Invoke-Build PostBuild $(ProjectDir)\..\.build.ps1 -Configuration $(ConfigurationName)

Or even simpler with one of the ib commands:

ib PostBuild $(ProjectDir)\..\.build.ps1 -Configuration $(ConfigurationName)

Other tasks are typical: clean, test, build and test help, create packages. Both projects use Invoke-Build for testing, each test is represented by a task in a test build script.


PowerShellTraps

PowerShellTraps/.build.ps1

This project is a collection of PowerShell issues described by markdown files, demo scripts, and test scripts. There is nothing to "build" here. The build script is for testing, generating the index, and other routine tasks.


FarNet family (C++, C#, PowerShell)

This project maintains the complex build system where Invoke-Build and MSBuild work together and call each other, Invoke-Build directly, MSBuild from post build events.

Parent project scripts dispatch common tasks like build, install, clean to child scripts, some of them dispatch these tasks further to their children.


PowerShell/PSReadLine

PSReadline.build.ps1

A bash inspired readline implementation for PowerShell.


PowerShell/vscode-powershell

vscode-powershell.build.ps1

PowerShell extension for Visual Studio Code.


PowerShell/PowerShellEditorServices

PowerShellEditorServices.build.ps1

A common platform for PowerShell development support in any editor or application.


Microsoft/PSRule

pipeline.build.ps1

Validate infrastructure as code (IaC) and objects using PowerShell rules.


Badgerati/Pode

pode.build.ps1

PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers.


AtlassianPS/JiraPS

JiraPS.build.ps1

PowerShell module to interact with Atlassian JIRA.


red-gate build scripts

Some red-gate projects use Invoke-Build scripts:


Format PowerShell Code Module

zloeber/FormatPowershellCode/.build.ps1

It is one of the most evolved Invoke-Build scripts. It puts together a lot of typical project tasks with complex relations.


MathieuBuisson/PSCodeHealth

PSCodeHealth.build.ps1

PowerShell module gathering PowerShell code quality and maintainability metrics.


Clone this wiki locally