Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Internal / BuildEngine4.cs
index e415f187e9417b4ada8e571658b1b84bec1f2377..4eebb8ac1e2a6a76f54e23dde4d859d91727e422 100644 (file)
@@ -35,6 +35,7 @@ using System.Linq;
 using System.IO;
 using Microsoft.Build.Exceptions;
 using System.Globalization;
+using Microsoft.Build.Construction;
 
 namespace Microsoft.Build.Internal
 {
@@ -161,6 +162,7 @@ namespace Microsoft.Build.Internal
 
                        // null key is allowed and regarded as blind success(!) (as long as it could retrieve target)
                        if (!request.ProjectInstance.Targets.TryGetValue (targetName, out target))
+                               // FIXME: from MSBuild.exe it is given MSB4057. Can we assign a number too?
                                throw new InvalidOperationException (string.Format ("target '{0}' was not found in project '{1}'", targetName, project.FullPath));
                        else if (!args.Project.EvaluateCondition (target.Condition)) {
                                LogMessageEvent (new BuildMessageEventArgs (string.Format ("Target '{0}' was skipped because condition '{1}' was not met.", target.Name, target.Condition), null, null, MessageImportance.Low));
@@ -179,9 +181,10 @@ namespace Microsoft.Build.Internal
                        
                                event_source.FireTargetStarted (this, new TargetStartedEventArgs ("Target Started", null, target.Name, project.FullPath, target.FullPath));
                                try {
-                                       if (!string.IsNullOrEmpty (target.Inputs) != !string.IsNullOrEmpty (target.Outputs)) {
+                                       // FIXME: examine in which scenario Inputs/Outputs inconsistency results in errors. Now it rather prevents csproj build.
+                                       /*if (!string.IsNullOrEmpty (target.Inputs) != !string.IsNullOrEmpty (target.Outputs)) {
                                                targetResult.Failure (new InvalidProjectFileException (target.Location, null, string.Format ("Target {0} has mismatching Inputs and Outputs specification. When one is specified, another one has to be specified too.", targetName), null, null, null));
-                                       } else {
+                                       } else*/ {
                                                bool skip = false;
                                                if (!string.IsNullOrEmpty (target.Inputs)) {
                                                        var inputs = args.Project.GetAllItems (target.Inputs, string.Empty, creator, creator, s => true, (t, s) => {
@@ -224,7 +227,8 @@ namespace Microsoft.Build.Internal
                {
                        return outputs.Where (o => !File.Exists (o.GetMetadata ("FullPath")) || inputs.Any (i => string.CompareOrdinal (i.GetMetadata ("LastModifiedTime"), o.GetMetadata ("LastModifiedTime")) > 0));
                }
-               
+
+               // FIXME: Exception should be caught at caller site.
                bool DoBuildTarget (ProjectTargetInstance target, TargetResult targetResult, InternalBuildArguments args)
                {
                        var request = submission.BuildRequest;
@@ -274,7 +278,7 @@ namespace Microsoft.Build.Internal
                                        if (!RunBuildTask (target, ti, targetResult, args))
                                                return false;
                                }
-                       } catch {
+                       } catch (Exception ex) {
                                // fallback task specified by OnError element
                                foreach (var c in target.Children.OfType<ProjectOnErrorInstance> ()) {
                                        if (!args.Project.EvaluateCondition (c.Condition))
@@ -282,6 +286,10 @@ namespace Microsoft.Build.Internal
                                        foreach (var fallbackTarget in project.ExpandString (c.ExecuteTargets).Split (';'))
                                                BuildTargetByName (fallbackTarget, args);
                                }
+                               int line = target.Location != null ? target.Location.Line : 0;
+                               int col = target.Location != null ? target.Location.Column : 0;
+                               LogErrorEvent (new BuildErrorEventArgs (null, null, target.FullPath, line, col, 0, 0, ex.Message, null, null));
+                               targetResult.Failure (ex);
                                return false;
                        } finally {
                                // restore temporary property state to the original state.