Show better error location in InvalidProjectFileException.
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Thu, 21 Nov 2013 02:58:38 +0000 (11:58 +0900)
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Tue, 3 Dec 2013 07:51:54 +0000 (16:51 +0900)
mcs/class/Microsoft.Build/Microsoft.Build.Construction/ProjectElement.cs
mcs/class/Microsoft.Build/Microsoft.Build.Construction/ProjectElementContainer.cs
mcs/class/Microsoft.Build/Microsoft.Build.Exceptions/InvalidProjectFileException.cs

index 08805383ad442c25841604ce99c18ccd19d0c43b..6a3cd8f2f3b1ac922a4e0c075991fe6cb8252b1f 100644 (file)
@@ -88,7 +88,7 @@ namespace Microsoft.Build.Construction
                                 Condition = value;
                                 break;
                         default:
-                                throw new InvalidProjectFileException (string.Format (
+                                throw new InvalidProjectFileException (Location, null, string.Format (
                                         "Attribute \"{0}\" is not known on node \"{1}\" [type {2}].", name, XmlName,
                                         GetType ()));
                         }
@@ -126,7 +126,6 @@ namespace Microsoft.Build.Construction
                 
                 internal void FillLocation (XmlReader reader)
                 {
-#if NET_4_5
                         var l = reader as IXmlLineInfo;
                         if (l != null && l.HasLineInfo ())
                                 Location = new ProjectElementLocation (reader.BaseURI, l);
@@ -135,7 +134,6 @@ namespace Microsoft.Build.Construction
                         if (reader.MoveToAttribute ("Label") && l.HasLineInfo ())
                                 LabelLocation = new ProjectElementLocation (reader.BaseURI, l);
                         reader.MoveToElement ();
-#endif
                 }
                 
                 class ProjectElementLocation : ElementLocation
index 6f1c1ab99b7508c0eb6833353eee92f3a06af746..1f1619bbd53cf379f098d4648c0cd37f256fc06f 100644 (file)
@@ -128,10 +128,10 @@ namespace Microsoft.Build.Construction
                 {
                         reader.Read ();
                         reader.MoveToContent ();
+                        FillLocation (reader);
                         if (reader.LocalName != XmlName || reader.NamespaceURI != MSBuildNamespace)
                                 throw CreateError (reader, string.Format ("Unexpected XML {0} \"{1}\" in namespace \"{2}\" appeared, while \"{3}\" in namespace \"{4}\" is expected.",
                                                 reader.NodeType, reader.LocalName, reader.NamespaceURI, XmlName, MSBuildNamespace), -1);
-                        FillLocation (reader);
                         while (reader.MoveToNextAttribute ()) {
                                 LoadAttribute (reader.Name, reader.Value);
                         }
index 895700e15342111f50f4966bef34dea761bd80a2..806c4f33b5fef293e8ac9d09bb120e8e6739f787 100644 (file)
@@ -109,8 +109,15 @@ namespace Microsoft.Build.Exceptions
                 public string HelpKeyword { get; private set; }
                 public int LineNumber { get; private set; }
                 public override string Message {
-                        get { return ProjectFile == null ? base.Message : base.Message + " " + ProjectFile; }
+                        get { return ProjectFile == null ? base.Message : base.Message + " " + GetLocation (); }
                 }
                 public string ProjectFile { get; private set; }
+
+                string GetLocation ()
+                {
+                        string start = LineNumber == 0 ? string.Empty : ColumnNumber > 0 ? string.Format ("{0},{1}", LineNumber, ColumnNumber) : string.Format ("{0}", LineNumber);
+                        string end = EndLineNumber == 0 ? string.Empty : EndColumnNumber > 0 ? string.Format (" - {0},{1}", EndLineNumber, EndColumnNumber) : string.Format (" - {0}", EndLineNumber);
+                        return LineNumber == 0 ? ProjectFile : String.Format (" at: {0} ({1}{2})", ProjectFile, start, end);
+                }
         }
 }