Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine If Solution Compiles using MSBuild and PSake

I have put together a PSake (v2.0) build script, and the script is setting the $psake.build_success property as true even thought the call to MSBuild fails. Can anyone advise me on how to alter the script so that the $psake.build_success property will correctly return false when the MSBuild call fails?

My PSake build script is as follows:

properties {
    $solutionFile = 'SOLUTION_FILE'
    $buildSuccessfulMessage = 'Solution Successfully Built!'
    $buildFailureMessage = 'Solution Failed to Build!'
    $cleanMessage = 'Executed Clean!'
}

task default -depends BuildSolution 

task BuildSolution
{
    msbuild $solutionFile /t:Clean,Build
    if ($psake.build_success) 
    {
        $buildSuccessfulMessage
    } 
    else 
    {
        $buildFailureMessage
    }
}
like image 863
Tangiest Avatar asked Mar 14 '26 19:03

Tangiest


1 Answers

Is PowerShell's native $lastExitCode (i.e., WIn32 ExitCode) any use in the context? I'd be guessing that the built in one is only relevant when you're invoking a psake-related cmdlet.

i.e., replace the check with

if($lastexitcode -eq 0) {

Disclaimer: Only podcast level experience with psake :D

like image 172
Ruben Bartelink Avatar answered Mar 17 '26 15:03

Ruben Bartelink