Skip to content
Wojtek edited this page May 8, 2015 · 4 revisions

Fast introduction

Please execute PS> Get-Help .\psmake.ps1 -Detailed to see detailed help with examples.

Command list

  1. General parameters
  2. Making a project (-Target)
  3. Listing available modules (-ListAvailableModules)
  4. Listing current modules (-ListModules)
  5. Adding module (-AddModule)
  6. Updating modules (-UpdateAllModules)
  7. Scaffolding (-Scaffold)
  8. PsMake version (-GetVersion)

General parameters

.\psmake.ps1 ... [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole]

PsMake has defined a set of general parameters, that are present for each command. Most of the operations that are executed by PsMake, requires NuGet.exe. PsMake offers a various ways to specify and configure NuGet parameters.

The -NuGetExe parameter is used to determine a path to NuGet.exe file. If it is not specified, PsMake will try to find a NuGet.exe in [working_directory]\.nuget directory. If exe does not exist on this path, it would assume that NuGet.exe is on PATH environment variable.

The -NuGetConfig parameter is used to determine a path to NuGet.Config file. If it is not specified, PsMake will try to find it in [working_directory]\.nuget directory. If file is not present there, NuGet.exe will be called without -ConfigFile parameter.

The -NuGetSource parameter is used to specify one or more sources that NuGet should use to fetch packages. If not specified, NuGet.exe will be called without -Source parameter, so it would use default list of sources defined in NuGet config files. Multiple sources have to be separated with semicolon ;.

PsMake usually requires an additional files to work. The bare minimum is Makefile.ps1 that contains definitions of steps to execute during make.

The -MakeDirectory parameter allows to specify a directory where PsMake should look for all configuration files. If not specified, a working directory would be used.

The -AnsiConsole parameter makes PsMake emitting ANSI escape sequences for colors specified for Write-Host cmdlet. While it is not necessary to specify it on Windows console, it may be helpful to colorize ANSI terminals. For example, this switch works well with AnsiColor Plugin to colorize build output on Jenkins.

Please note that all of above parameters, except -MakeDirectory, can be predefined in Defaults.ps1 file

Making a project

.\psmake.ps1 -Target <String> [-AdditionalParams <String[]>] [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This is a main command of PsMake. The simplest syntax to call it is .\psmake.ps1 -Target build, where build is an example target specified in Makefile.ps1. It results in execution of all steps defined in Makefile.ps1, that are assigned to target specified by -Target parameter.

The -AdditionalParams parameter allows to specify additional parameters that would be available for steps via $Context variable. Run Get-Help .\psmake.ps1 -Parameter AdditionalParams for details.

Please see Scaffolding section to read about make.ps1 wrapper script for psmake.ps1

Listing available modules

.\psmake.ps1 -ListAvailableModules [-ShowIdOnly] [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This command allows to list all available modules that could be used during make. When called, it uses NuGet to list all packages which ID starts with psmake.mod. and returns a hashtable with PackageID-Version pairs. It is possible to pipe this command for further results processing.

The -ShowIdOnly parameter changes the output to an array of PackageIDs.

Listing current modules

.\psmake.ps1 -ListModules [-ShowIdOnly] [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This command allows to list all modules that are currently used during make. Physically, it outputs all modules specified in Modules.ps1 file in a form of hashtable with PackageID-Version pairs. It is possible to pipe this command for further results processing.

The -ShowIdOnly parameter changes the output to an array of PackageIDs.

Adding module

.\psmake.ps1 -AddModule -ModuleName <String> -ModuleVersion <String> [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This command allows to add a new module to Modules.ps1 file. The -ModuleName parameter specifies package ID that should be added. It has to start with psmake.mod.. The -ModuleVersion parameter specifies package version.

Please note that by default, methods defined in modules are not available in step methods. They have to be imported explicitly by calling . (Require-Module 'psmake.mod.[name]') or its alias, . (require 'psmake.mod.[name]').

Updating modules

.\psmake.ps1 -UpdateAllModules [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This command allows to update all currently installed modules to their newest versions that are available.

Scaffolding

.\psmake.ps1 -Scaffold <String> [-MakeDirectory <String>] [-NuGetSource <String>] [-NuGetExe <String>] [-NuGetConfig <String>] [-AnsiConsole] [<CommonParameters>]

This command allows to generate scaffold for PsMake config files.

The -Scaffold parameter allows to specify a type of scaffold. At this point, it is possible to specify only empty type.

All files generated by this command would be placed in make directory specified by -MakeDirectory parameter (. by default). Below there is a list of files that would be generated:

  • Makefile.ps1 - it would contain an example definition of two steps,
  • Defaults.ps1 - it would contain NuGetSource / NuGetConfig values, if such parameters have been specified,
  • make.ps1 - a wrapper script.

The make.ps1 is a wrapper script that can be used during automated builds to make a project. It ensures that a proper version of PsMake is installed before run, and fetches it if not present, which means that PsMake package does not have to be stored together with project code in repository. Also, wrapper script passes a -MakeDirectory parameter to psmake.ps1, which simplifies usage to .\make.ps1 -Target [target] or makeDirectory\make.ps1 -Target [target]. It supports also all parameters that are supported by psmake.ps1.

PsMake version

.\psmake.ps1 -GetVersion [-AnsiConsole] [<CommonParameters>]

This command returns a PsMake version string.

Continue reading: 02 Makefile.ps1