Skip to content

Portable Build Scripts

Roman Kuzmin edited this page Jun 16, 2017 · 9 revisions

It is possible and even expected in some cases to have a copy of Invoke-Build tools kept together with build scripts (Invoke-Build.ps1 is often enough). This makes the build tool set portable, i.e. build scripts can be invoked on any machine without Invoke-Build in the path.

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 Invoke-Builds.ps1 are already portable. Otherwise in order to be portable build scripts should follow one simple rule: invoke tools by aliases Invoke-Build or Invoke-Builds, not by 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;
  • Invoke-Builds is an alias of the script Invoke-Builds.ps1 in the same directory.
  • Resolve-MSBuild is an alias of the script 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 should invoke builds as Invoke-Build.ps1 (assuming it is in the path) or FullOrRelativePath\Invoke-Build.ps1 (assuming it is there).