3

PSake (v2.0) ビルド スクリプトをまとめましたが、MSBuild の呼び出しが失敗した$psake.build_successとしても、スクリプトはプロパティを設定しています。MSBuild の呼び出しが失敗したときにプロパティが正しく返されるtrueように、スクリプトを変更する方法を教えてもらえますか?$psake.build_successfalse

私の PSake ビルド スクリプトは次のとおりです。

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
    }
}
4

4 に答える 4

3

PowerShell のネイティブ$lastExitCode(つまり、WIN32 ExitCode) はコンテキストで使用されますか? 組み込みのものは、psake 関連のコマンドレットを呼び出している場合にのみ関連すると思います。

つまり、チェックを

if($lastexitcode -eq 0) {

免責事項: psake でのポッドキャスト レベルの経験のみ:D

于 2009-12-01T12:39:49.813 に答える
3

問題は、MSBuild 操作の呼び出しが実際には正常に完了し、それが開始するビルド操作が失敗することです。これを回避する方法は、MSBuild 呼び出しの出力をテキスト ファイルにパイプし、そのファイルを "Build Failed" という文字列で解析することでした。文字列が含まれている場合、明らかにビルドは失敗しています。

私の PSake ビルド スクリプトは次のとおりです。

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 
}

そして私の呼び出しスクリプトで:

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)
}
于 2009-12-01T16:30:47.107 に答える
1

msbuild をラップできるpsake Execコマンドがあり、powershell エラーがスローされます。

Exec {
     msbuild $solutionFile "/p:Configuration=$buildConfiguration;Platform=$buildPlatform;OutDir=$tempOutputDirectory"
}
于 2016-04-03T05:51:13.277 に答える
0

$LastExitCode も $_ も機能しませんでした。ただし、これは次のことを行いました。

$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これを本番環境で使用する場合は、 -timeout 処理を Wait-Process に追加することをお勧めします

于 2014-01-30T19:02:31.123 に答える