Skip to content

Comparison with MSBuild

Roman Kuzmin edited this page Apr 13, 2014 · 31 revisions

MSBuild is yet another build automation tool, part of the .NET Framework. Invoke-Build is designed to be very similar. Of course, their scripts use different languages (PowerShell and XML) and different built-in and external tools. But build flow, script structure, and main concepts are mostly the same.

MSBuild                      Invoke-Build
-------                      ------------
Default build script         A single *.build.ps1 or .build.ps1
InitialTargets               Whatever a build script invokes
DefaultTargets               The . or the first added task
Properties                   Script/environment variables
Import                       Dot-source or invoke
Target                       Task
Condition                    -If
Inputs, Outputs              -Inputs -Outputs [-Partial]
DependsOnTargets             -Jobs, referenced tasks
Tasks                        -Jobs, script blocks
AfterTargets, BeforeTargets  -After, -Before

Remarks

MSBuild targets consist of calls to build-in or external tools. Invoke-Build tasks consist of PowerShell script blocks. Unlike MSBuild, Invoke-Build does not provide numerous tools for scripts, PowerShell has enough tools. Still, some helpers are provided, like use, exec, assert, property.

Invoke-Build task jobs combine two MSBuild features: referenced targets and own target tasks. The parameter Jobs is a list of task references (analogue of DependsOnTargets) and script blocks (analogue of MSBuild tasks). Thus, jobs define classic MSBuild scenarios (referenced tasks first, own scripts second) and new scenarios with referenced tasks after or even between script jobs.

Invoke-Build "properties" are usual PowerShell script variables and parameters, just like MSBuild properties defined in XML scripts (variables) and properties that come from command lines (parameters). MSBuild also deals with environment variables using the same syntax. In contrast, Invoke-Build scripts should either use them explicitly as $env:Name or get by the helper property.

MSBuild lets to ignore some errors and perform actions on errors. Invoke-Build also lets to deal with errors: some tasks are allowed to fail without breaking the build and then downstream tasks can analyse these errors.