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.