Click here to Skip to main content
15,888,351 members
Articles / BUILD

Passing Command Line Parameters into a PSake Build Script

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
7 Jan 2016CPOL 6.1K  
This article assumes the reader is familiar with James Kovac's PowerShell based build language, PSake, and explains how to pass parameters from the command line and use them within a PSake build script.

The issue addressed in this article came about as a result of my needing to pass the Visual Studio build configuration (Debug, Release, etc.) into my PSake script so that I could use it within my compile task. Initially, I had separate DebugCompile and ReleaseCompile tasks that hard coded the configuration, but were otherwise identical. Nasty build code duplication removed. Nice.

The command line code that calls my build script assumes that I've included the PSake script files in a Libraries folder within my project structure and that the build script itself resides within a build folder. The taskList argument provides the initial starting point highlighted in the build script snippet below. If you need to pass in multiple parameters, separate them with a semicolon.

& { .\libraries\psake\psake .\build\build.ps1 -taskList ReleaseBuild -parameters @{config='Release'}

The build script snippet just shows the part of my PSake build script that handles the compilation of the solution, whilst making use of the config parameter value passed in:

task ReleaseBuild -depends Compile

task Compile {
    Write-Host "Compiling $solution_name in $config mode" -ForegroundColor Green
    Exec { msbuild "$solution_file" /t:Clean /t:Build /p:Configuration=$config /v:q /nologo }
}

The actual ReleaseBuild task also makes use of other tasks, including running unit and acceptance tests, updating config files and deploying the website to a specific target folder.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Levelnis Ltd
United Kingdom United Kingdom
Follow along my journey as I create a newsletter about launching websites. Just message me with "I'm in" and I'll add you

Comments and Discussions

 
-- There are no messages in this forum --