Skip to content

Comparison with MSBuild

Roman Kuzmin edited this page Dec 24, 2012 · 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 almost 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 have to provide numerous tools for scripts, PowerShell has enough tools. Only a few extra helpers like use, exec, assert, property are added.

Invoke-Build task jobs combine two MSBuild features together: dependent targets and own target tasks. The parameter Jobs is a list of strings (dependent task names, analogue of dependent targets) and script blocks (analogue of own target tasks). Thus, Jobs can define classic MSBuild scenarios (dependent tasks first, own scripts second) and more scenarios with dependent 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 downstream tasks can analyse these errors.