cake-build/cake — pull request #45 by devlead (2014-06-24 21:33:43+00:00)
Title: Added support for custom error handling

Added CakeTaskBuilderExtensions Does overloads for possibility
to intercept and act on errors, with option to continue or fail
on error.

We can argue on implementation, for my need probably a simple Func is powerful & good enough.

Basically what this enables is build script like this:

var target = Argument("target", "Build");
var solution = Argument("solution", @".\src\test.sln");
var configuration = Argument("configuration", "Release");
var solutionDir = System.IO.Path.GetDirectoryName(solution);

Task("Clean")
.Does(() =>
{
// Clean directories.
CleanDirectories(solutionDir + "/**/bin/" + configuration);
CleanDirectories(solutionDir + "/**/obj/" + configuration);
});

Task("Restore")
.Does(() =>
{
NuGetRestore(solution,
settings=>settings.SetToolPath("C:/temp/priv/cakeTest/NuGet.exe")
.WithVerbosityDetailed());
throw new Exception("This error will be supressed");
},
error=>
{
//Do something
Console.Beep();
//report handled and continue on fail
return true;
}
);

Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.UseToolVersion(MSBuildToolVersion.NET45)
//.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration));
},
error=>
{
//Do something
Console.Beep();
//report step failed
return false;
});
RunTarget(target);