Determine if the solution will compile using MSBuild and PSake

I have compiled the PSake (v2.0) script assembly, and the script sets the property $psake.build_successas true, even assuming that the MSBuild call fails. Can someone advise me how to change the script so that the property $psake.build_successreturns correctly falsewhen the MSBuild call failed?

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
    }
}
+3
source share
4 answers

PowerShell native $lastExitCode (.. WIn32 ExitCode) ? , , psake.

i.e.,

if($lastexitcode -eq 0) {

: psake: D

+3

, MSBuild , , , . , , - MSBuild , "Build Failed". , , .

My PSake build script :

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

task default -depends Build 

task Build -depends Clean {
    msbuild $solutionFile /t:Build /p:Configuration=Release >"MSBuildOutput.txt"
}

task Clean {
    msbuild $solutionFile /t:Clean 
}

script:

function Check-BuildSuccess()
{
    return (! (Find-StringInTextFile  -filePath .\MSBuildOutput.txt -searchTerm "Build Failed"))
}

function Is-StringInTextFile
(
    [string]$filePath = $(Throw "File Path Required!"),
    [string]$searchTerm = $(Throw "Search Term Required!")
)
{
    $fileContent = Get-Content $filePath    
    return ($fileContent -match $searchTerm)
}
+3

psake Exec, msbuild, powershell.

Exec {
     msbuild $solutionFile "/p:Configuration=$buildConfiguration;Platform=$buildPlatform;OutDir=$tempOutputDirectory"
}
+1

None used $ LastExitCode or $ _ for me. However, it did:

$buildArgs = "MySolution.sln", "/t:Build", "/p:Configuration=Debug"
$procExitCode = 0
$process = Start-Process -FilePath "msbuild" -ArgumentList $buildArgs -NoNewWindow -PassThru
Wait-Process -InputObject $process
$procExitCode = $process.ExitCode

#aha! msbuild sets the process exit code but powershell doesn't notice
if ($procExitCode -ne 0)
{
    throw "msbuild failed with exit code $procExitCode."
}

PS If you use this in production, I recommend adding time processing to Wait-Process.

0
source

Source: https://habr.com/ru/post/1724376/


All Articles