Skip to content

Portable Build Scripts

Roman Kuzmin edited this page Nov 13, 2017 · 9 revisions

It is possible and sometimes expected to have a copy of Invoke-Build tools kept together with build scripts. This makes the build tool set portable, i.e. build scripts can be invoked on any machine without Invoke-Build installed.

Another reason to keep a copy of Invoke-Build with scripts is use of multiple build engine versions, potentially incompatible. Existing build scripts do not have to be upgraded for a newer version, they may continue to use the old copy.

Build scripts which do not call Invoke-Build.ps1 and Build-Parallel.ps1 are already portable. Otherwise in order to be portable build scripts should follow the simple rule: always invoke tools by the predefined aliases Invoke-Build and Build-Parallel, i.e. avoid using script names with extensions.

These aliases are predefined by the engine and associated with exactly those scripts that are currently running. Namely:

  • Invoke-Build is an alias of the currently running script Invoke-Build.ps1;
  • Build-Parallel is an alias of Build-Parallel.ps1 in the same directory.
  • Resolve-MSBuild is an alias of Resolve-MSBuild.ps1 in the same directory.

Thus, nested calls of Invoke-Build from tasks invoke Invoke-Build.ps1 which is currently running, e.g. which is kept together with the scripts. Compare: calls to Invoke-Build.ps1, i.e. with the extension, may fail because either Invoke-Build.ps1 is not in the path on the machine or it is incompatible.

Only top level commands may invoke builds as Invoke-Build.ps1 (assuming it is in the path) or FullOrRelativePath\Invoke-Build.ps1 (assuming it is there).