Psake: Build automation with PowerShell

With any edition of Chocolatey , you can host your own packages and cache or internalize existing community packages. If you are an organization using Chocolatey, we want your experience to be fully reliable. Due to the nature of this publicly offered repository, reliability cannot be guaranteed. To get a complete list of all parameters possible for each task, Coding Resources for Beginners has built-in help. This makes it easy to scour through all of the options available.

  • Since just about every ops person has some PowerShell command-line knowledge, wouldn’t it be nice to use that skill and apply it to the software build process?
  • At a minimum, a task should have a name and an action block.
  • PowerShell folks can run the PowerShell scripts directly.

Bottom Up Mergesort GitHub uses VSSetup to locate msbuild when using Visual Studio 2017. The VSSetup PowerShell module must be installed prior to compiling a VS2017 project with psake. Install instructions for VSSetup can be found here and here. Configure-build.ps1 – this script is called first, which configures the dependencies. In another blog post we looked atCake, which is the C# cousin of psake. You’ll see that at its heart, psake is just a task management engine made for software builds.

Step 1: Review Your Packages

When you then invoke the PSake file with Invoke-PSake, you would then see the following output. Notice that the $SqlYear and $SqlVersion variables have been expanded with the values defined in the Properties block. For example, to pass dynamic SqlYear and SqlVersion variables to each task in the PSake file, you can define them as shown below. To pass parameters to PSake files, you can use a Properties block that defines key/value pairs which PSake then makes available inside of each task in the file. You can use the PreCondition parameter to execute a piece of code that returns either a boolean True or False that dictates whether or not that task runs. Assuming you have the PSake project from GitHub on your local machine, you’ll first need to run through a few steps to get it set up.

You will need to “unblock” the zip file before extracting – PowerShell by default does not run files downloaded from the Internet. Just right-click the zip and click on “properties” and click on the “unblock” button. To run a specific task, we can execute by passing a task or alias as a command argument. E.g. build.cmd DevPublish, build.cmd dp, build.cmd cp, ./ DevPublish, ./ dp, ./ cp, etc.

Since any task can be executed when invoking psake, make sure that each one has appropriate dependencies. For exampleTestdepends onCompilethat in turn depends onInit. If no task is specified forInvoke-psake, one nameddefaultwill be executed. Each task can have multiple dependent tasks that will run before it. Here are high-level tasks that just have dependencies and don’t have a ScriptBlock themselves.

Package Details

Since just about every ops person has some PowerShell command-line knowledge, wouldn’t it be nice to use that skill and apply it to the software build process? 28.9K Hangfire.Build Psake tasks and functions to build Hangfire projects with ease. When you call the psake.ps1 script, it forwards the parameters on to the Invoke-psake function.


Psake is a build automation tool written in PowerShell. Create a script named psakefile.ps1 with a single task. At a minimum, a task should have a name and an action block.


Build Reusable Functions – these are some of the basic powershell functions we need to build, so that use them later in the process. Properties and parameters to psake can be a bit confusing. Thepsake documentationexplains it pretty well, and thisgisthas examples of the various combinations. The following list are the basic steps to get building with psake. This functionality was working perfectly fine and then suddenly stopped working. No changes were made to project files or VS Code besides monthly updates.

PsInfo, a command-line tool that is part of the Sysinternals suite, gets key information about Windows systems, such as… Get many of our tutorials packaged as an ATA Guidebook. PostAction – A script block to run right after the task has completed with success. PreAction – A script block to run prior to the task. Time summary with the duration of each task, plus the total duration of the whole script. Extract the PSake zip file downloaded from GitHub.

This discussion is only about psake and the psake package. If you have feedback for Chocolatey, please contact the Google Group. In cases where actual malware is found, the packages are subject to removal. Welcome to the Chocolatey Community Package Repository!


Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes. Your use of the packages on this site means you understand they are not supported or guaranteed in any way. For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI. We recently released our largest update to Chocolatey Central Management so far.

To make sure you have all dependencies installed , you can wrap psake with a simple script to install such modules. This is helpful when running in an Azure DevOps pipeline that’s on a hosted machine since it may not have what you need to run the build. The script below is a sample that installs psake, SQL Change Automation, and VsSetup then callInvoke-psakewith parameters. Also check out the psake-contrib project for scripts, modules and functions to help you with a build.


Clean the solution using dotnet clean command, in addition to directories like bin, obj, etc. Function that can delete a directory, whether empty or not, we use here in cleanup tasks. Let’s build these files Why No Developer Should Count To 10,000 Hours by Ken Mazaika one by one with minimal implementation. If you still hear nothing back, please follow the package triage process. See infrastructure management matrix for Chocolatey configuration elements and examples.

Step 5: Copy Your Script

PowerShell folks can run the PowerShell scripts directly. If you have devs that may have trouble with that, you can create a .bat file that launches PowerShell.exe like this, which they can double click from explorer. Each of these tasks is defined inside of a single pssakefile.ps1 script. If you anticipate adding more many more tasks over time, you should split those tasks up into separate files with each task inside e.g. ValidateDiskSpace.ps1, DownloadSql.ps1, InstallSqlDriveD.ps1, InstallSqlDriveD.ps1, etc.

This has led ops guys and gals to adapt their existing knowledge to software development concepts. It is comprised of multipletaskfunction calls that are passed ScriptBlocks of code you want to execute for each step of the build process. To avoid making this file long and noisy, you can create functions in separate files and dot-source them into this one. You can install psake by adding the psake NuGet package to a project in your solution. Otherwise the psake GitHub site has directions for installing it. Note that to run unsigned PowerShell scripts locally, you should issue the following command from an Administrative PowerShell prompt.

The depends parameter is just one of many useful parameters you can pass to each task. Also useful are a couple of the validation parameters called precondition and requiredvariable. The precondition parameter allows you to define code that will return either $true or $false. If it returns $false, the task will not run at all. You can see that psake executed a PowerShell script, which contained three tasks called Clean, Compile, and Test. Psake allows you to define these tasks and any dependencies required among them to execute PowerShell code within each task.

When I try to build using I am getting an error when the build is invoked using Invoke-PSake. Share your experiences with the package, or extra configuration or gotchas that you’ve found. Tell us what you love about the package or psake, or tell us what needs improvement.

You still need to keep the Properties block at the top of psakefile.ps1 as in the example above, but PSake lets you override the values. For example, maybe you have a Pester test to confirm the SQL setup ZIP file exists in a folder after you run the DownloadSql task. In that case, you build a simple Pester test and invoke the DownloadSql task within the test and check for the ZIP file right after it runs.

Leave a Reply

Your email address will not be published. Required fields are marked *