For ItemType-less metadata expression, apply all items in the project.
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Wed, 27 Nov 2013 15:55:56 +0000 (00:55 +0900)
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Fri, 29 Nov 2013 09:24:08 +0000 (18:24 +0900)
mcs/class/Microsoft.Build/Microsoft.Build.Execution/ProjectInstance.cs
mcs/class/Microsoft.Build/Microsoft.Build.Internal/ExpressionEvaluator.cs

index 968062fa025426fe13d2fd8fc77b05b308d91619..5edaa5007c7d33f7cf14274ae0b640be588f562d 100644 (file)
@@ -273,6 +273,10 @@ namespace Microsoft.Build.Execution
                        }
                }
 
+               internal IEnumerable<ProjectItemInstance> AllEvaluatedItems {
+                       get { return all_evaluated_items; }
+               }
+
                public List<string> DefaultTargets { get; private set; }
                
                public string Directory {
index b03e23a4bef9994939e396f041af09bac9c407b8..f91a9cfbb759524465dfe9acbd52eda063981720 100644 (file)
@@ -127,6 +127,14 @@ namespace Microsoft.Build.Internal.Expressions
                        else
                                return Evaluator.ProjectInstance.GetItems (name);
                }
+
+               public IEnumerable<object> GetAllItems ()
+               {
+                       if (Evaluator.Project != null)
+                               return Evaluator.Project.AllEvaluatedItems;
+                       else
+                               return Evaluator.ProjectInstance.AllEvaluatedItems;
+               }
                
                public string EvaluateItem (string itemType, object item)
                {
@@ -422,7 +430,7 @@ namespace Microsoft.Build.Internal.Expressions
                
                public override string EvaluateAsString (EvaluationContext context)
                {
-                       string itemType = this.Access.ItemType.Name;
+                       string itemType = this.Access.ItemType != null ? this.Access.ItemType.Name : null;
                        string metadataName = Access.Metadata.Name;
                        IEnumerable<object> items;
                        if (this.Access.ItemType != null)
@@ -430,7 +438,7 @@ namespace Microsoft.Build.Internal.Expressions
                        else if (context.ContextItem != null)
                                items = new Object [] { context.ContextItem };
                        else
-                               throw new InvalidProjectFileException (Location, null, string.Format ("Unexpected occurence of metadata reference: {0}{1}", itemType != null ? itemType + '.' : null, metadataName), null, null);
+                               items = context.GetAllItems ();
                        
                        var values = items.Select (i => (i is ProjectItem) ? ((ProjectItem) i).GetMetadataValue (metadataName) : ((ProjectItemInstance) i).GetMetadataValue (metadataName)).Where (s => !string.IsNullOrEmpty (s));
                        return string.Join (";", values);