Merge pull request #1508 from slluis/fix-20966
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / Project.cs
index 660c14cb19cc8721d98f3300b629855378d4068a..005752baf98e12f541683c8aa9f258b6a7d03354 100644 (file)
@@ -38,6 +38,7 @@ using System.Text;
 using System.Xml;
 using System.Xml.Schema;
 using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
 using Mono.XBuild.Framework;
 using Mono.XBuild.CommandLine;
 
@@ -322,9 +323,7 @@ namespace Microsoft.Build.BuildEngine {
                                Reevaluate ();
                        }
 
-#if NET_4_0
                        ProcessBeforeAndAfterTargets ();
-#endif
 
                        if (targetNames == null || targetNames.Length == 0) {
                                if (defaultTargets != null && defaultTargets.Length != 0) {
@@ -403,7 +402,6 @@ namespace Microsoft.Build.BuildEngine {
                        return sb.ToString ();
                }
 
-#if NET_4_0
                void ProcessBeforeAndAfterTargets ()
                {
                        var beforeTable = Targets.AsIEnumerable ()
@@ -439,7 +437,6 @@ namespace Microsoft.Build.BuildEngine {
                        expr.Parse (targets, ParseOptions.AllowItemsNoMetadataAndSplit);
                        return (string []) expr.ConvertTo (this, typeof (string []));
                }
-#endif
 
                [MonoTODO]
                public string [] GetConditionedPropertyValues (string propertyName)
@@ -949,8 +946,12 @@ namespace Microsoft.Build.BuildEngine {
                                        case  "Choose":
                                                AddChoose (xe, ip);
                                                break;
+                                       case "ItemDefinitionGroup":
+                                               AddItemDefinitionGroup (xe);
+                                               break;
                                        default:
-                                               throw new InvalidProjectFileException (String.Format ("Invalid element '{0}' in project file '{1}'.", xe.Name, ip.FullFileName));
+                                               var pf = ip == null ? null : string.Format (" '{0}'", ip.FullFileName);
+                                               throw new InvalidProjectFileException (String.Format ("Invalid element '{0}' in project file{1}.", xe.Name, pf));
                                        }
                                }
                        }
@@ -1032,13 +1033,13 @@ namespace Microsoft.Build.BuildEngine {
                        SetExtensionsPathProperties (DefaultExtensionsPath);
                        evaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectDefaultTargets", DefaultTargets, PropertyType.Reserved));
                        evaluatedProperties.AddProperty (new BuildProperty ("OS", OS, PropertyType.Environment));
-#if NET_4_5    
+#if XBUILD_12
                        // see http://msdn.microsoft.com/en-us/library/vstudio/hh162058(v=vs.120).aspx
                        if (effective_tools_version == "12.0") {
                                evaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsPath32", toolsPath, PropertyType.Reserved));
-                               string frameworkToolsPath = parentEngine.Toolsets [effective_tools_version].FrameworkToolsPath;
-                               if (frameworkToolsPath == null)
-                                       throw new Exception (String.Format ("Invalid tools version '{0}', no framework tools path set for this.", effective_tools_version));                            
+
+                               var frameworkToolsPath = ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version451);
+
                                evaluatedProperties.AddProperty (new BuildProperty ("MSBuildFrameworkToolsPath", frameworkToolsPath, PropertyType.Reserved));
                                evaluatedProperties.AddProperty (new BuildProperty ("MSBuildFrameworkToolsPath32", frameworkToolsPath, PropertyType.Reserved));
                        }
@@ -1118,8 +1119,7 @@ namespace Microsoft.Build.BuildEngine {
                {
                        // eval all the properties etc till the import
                        if (evaluate_properties) {
-                               groupingCollection.Evaluate (EvaluationType.Property);
-                               groupingCollection.Evaluate (EvaluationType.Choose);
+                               groupingCollection.Evaluate (EvaluationType.Property | EvaluationType.Choose);
                        }
                        try {
                                PushThisFileProperty (importingProject != null ? importingProject.FullFileName : FullFileName);
@@ -1139,8 +1139,7 @@ namespace Microsoft.Build.BuildEngine {
                {
                        // eval all the properties etc till the import group
                        if (evaluate_properties) {
-                               groupingCollection.Evaluate (EvaluationType.Property);
-                               groupingCollection.Evaluate (EvaluationType.Choose);
+                               groupingCollection.Evaluate (EvaluationType.Property | EvaluationType.Choose);
                        }
                        string condition_attribute = xmlElement.GetAttribute ("Condition");
                        if (!ConditionParser.ParseAndEvaluate (condition_attribute, this))
@@ -1159,6 +1158,17 @@ namespace Microsoft.Build.BuildEngine {
                        }
                }
 
+               void AddItemDefinitionGroup (XmlElement xmlElement)
+               {
+                       string condition_attribute = xmlElement.GetAttribute ("Condition");
+                       if (!ConditionParser.ParseAndEvaluate (condition_attribute, this))
+                               return;
+
+                       foreach (XmlNode xn in xmlElement.ChildNodes) {
+                               // TODO: Add all nodes to some internal dictionary?
+                       }
+               }
+
                bool AddSingleImport (XmlElement xmlElement, string projectPath, ImportedProject importingProject, string from_source_msg)
                {
                        Import import = new Import (xmlElement, projectPath, this, importingProject);
@@ -1415,6 +1425,10 @@ namespace Microsoft.Build.BuildEngine {
                        return default (T);
                }
 
+               internal string ThisFileFullPath {
+                       get { return this_file_property_stack.Peek (); }
+               }
+
                // Used for MSBuild*This* set of properties
                internal void PushThisFileProperty (string full_filename)
                {