Simple Build Automation with psake
James Kovacs, the project owner, explains what is the improvement brought by psake:
It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge.
Beside making it compatible with PS 2.0, in version 2.01 psake has been rewritten as a PS module. The main benefits would be:
- Build scripts don't need to know where psake is installed, they just call Invoke-psake and it works.
- Encapsulation. Global variables are no longer required since they can be private to a module unless explicitly exported.
- Modules can be unloaded if needed which removes all the code and variables from memory.
Other enhancements in 2.01 are:
- Coding style is different.
- Try/Catch is used instead of the "Trap" statement.
- Got rid of the "exec" function.
- You can now define "Pre" and "Post" actions for a task.
- You can define how the task name will be formatted.
- You can define a "TaskSetup" function that will be executed before every task (took that from NUnit).
- You can define a "TaskTearDown" function that will be executed after every task (took that from NUnit too).
- Create a global variable called "psake_buildSucceeded" that will be set to true if the build succeeds - scripts can check this.
- Also added a "$noexit" switch to Run-Psake so that the function will not use the exit() function so that you can test a build script at the command line without PS closing down (the default behavior when the build fails is to call exit(1) so that the calling code can determine if the build failed or not).
- The psake-buildTester.ps1 had to be changed slightly in order for it to call the Invoke-psake function.
- Added more examples in the .\examples folder for POST conditions, PRE and POST Actions, etc.
Ayende Rahien wrote about using psake to build his Rhino Tools. The project initially used a NAnt-based built tool which turned out to be too complex, tending to create “zones of ‘there be dragons’, where only the initiated go, and even they go with trepidation.” After evaluating the possibility to use Rake or Bake, Rahien turned toward psake which did the job in 50 lines.
Keith Adams Dec 06, 2013