void EvaluateBuildPropertyGroup(BuildPropertyGroup bpg)
 {
     project.PushThisFileProperty(bpg.DefinedInFileName);
     try {
         if (ConditionParser.ParseAndEvaluate(bpg.Condition, project))
         {
             bpg.Evaluate();
         }
     } finally {
         project.PopThisFileProperty();
     }
 }
示例#2
0
文件: Project.cs 项目: nikson/msbuild
        /// <summary>
        /// Process each of the direct children beneath the &gt;Project&lt; element.
        /// These include things like &lt;PropertyGroup&gt;, &lt;ItemGroup&gt;, &lt;Target&gt;, etc.
        /// This method is simply capturing the data in the form of our own
        /// internal objects.  It is not actually evaluating any of the properties
        /// or other data.
        /// </summary>
        /// <param name="projectElement"></param>
        /// <param name="projectDirectoryLocation"></param>
        /// <param name="importedProject"></param>
        /// <owner>RGoel</owner>
        private void ProcessProjectChildren
        (
            XmlElement projectElement,
            string projectDirectoryLocation,
            bool importedProject
        )
        {
            // Make sure the <Project> node has been given to us.
            error.VerifyThrow(projectElement != null,
                "Need an XML node representing the <project> element.");

            // Make sure this really is the <Project> node.
            ProjectXmlUtilities.VerifyThrowElementName(projectElement, XMakeElements.project);

            // Loop through all the direct children of the <project> element.
            // This verifies all the XML is legitimate, and creates ordered lists of objects
            // representing the top-level nodes (itemgroup, choose, etc.)
            // As this progresses, the Chooses and PropertyGroups are evaluated, so that conditions
            // on Imports involving properties can be evaluated too, because we need to know whether to
            // follow the imports.
            // All this comprises "Pass 1".
            List<XmlElement> childElements = ProjectXmlUtilities.GetValidChildElements(projectElement);

            string currentPerThreadProjectDirectory = Project.PerThreadProjectDirectory;

            try
            {
                // Make the correct project directory available. This is needed because it is 
                // used for evaluating "exists" in conditional expressions, for example on <Import> elements.
                Project.PerThreadProjectDirectory = ProjectDirectory;

                foreach (XmlElement childElement in childElements)
                {
                    switch (childElement.Name)
                    {
                        // Process the <ItemDefinitionGroup> element.
                        case XMakeElements.itemDefinitionGroup:
                            itemDefinitionLibrary.Add(childElement);
                            break;

                        // Process the <ItemGroup> element.
                        case XMakeElements.itemGroup:
                            BuildItemGroup newItemGroup = new BuildItemGroup(childElement, importedProject, /*parent project*/ this);
                            this.rawItemGroups.InsertAtEnd(newItemGroup);
                            break;

                    // Process the <PropertyGroup> element.
                    case XMakeElements.propertyGroup:
                        BuildPropertyGroup newPropertyGroup = new BuildPropertyGroup(this, childElement, importedProject);
                        newPropertyGroup.EnsureNoReservedProperties();
                        this.rawPropertyGroups.InsertAtEnd(newPropertyGroup);
                        // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether
                        // we include Imports.
                        newPropertyGroup.Evaluate(this.evaluatedProperties, this.conditionedPropertiesTable, ProcessingPass.Pass1);
                        break;

                        // Process the <Choose> element.
                        case XMakeElements.choose:
                            Choose newChoose = new Choose(this, this.rawGroups, childElement, importedProject, 0 /* not nested in another <Choose> */);

                            this.rawGroups.InsertAtEnd(newChoose);
                            // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether
                            // we include Imports.
                            newChoose.Evaluate(this.evaluatedProperties, false, true, this.conditionedPropertiesTable, ProcessingPass.Pass1);
                            break;

                        // Process the <Target> element.
                        case XMakeElements.target:
                            XmlElement targetElement = childElement;
                            Target newTarget = new Target(targetElement, this, importedProject);

                            // If a target with this name already exists, log a low priority message.
                            if (!ParentEngine.LoggingServices.OnlyLogCriticalEvents)
                            {
                                if (targets.Exists(newTarget.Name))
                                {
                                    ParentEngine.LoggingServices.LogComment(projectBuildEventContext, "OverridingTarget",
                                         targets[newTarget.Name].Name, targets[newTarget.Name].ProjectFileOfTargetElement,
                                         newTarget.Name, newTarget.ProjectFileOfTargetElement);
                                }
                            }

                            this.targets.AddOverrideTarget(newTarget);

                            if (this.nameOfFirstTarget == null)
                            {
                                this.nameOfFirstTarget = targetElement.GetAttribute(XMakeAttributes.name);
                            }
                            break;

                        // Process the <UsingTask> element.
                        case XMakeElements.usingTask:
                            UsingTask usingTask = new UsingTask(childElement, importedProject);
                            this.usingTasks.Add(usingTask);
                            break;

                        // Process the <ProjectExtensions> element.
                        case XMakeElements.projectExtensions:
                            if (!importedProject)
                            {
                                ProjectErrorUtilities.VerifyThrowInvalidProject(null == this.projectExtensionsNode, childElement,
                                    "DuplicateProjectExtensions");
                                this.projectExtensionsNode = childElement;

                                // No attributes are legal on this element
                                ProjectXmlUtilities.VerifyThrowProjectNoAttributes(childElement);
                            }
                            break;

                        // Process the <Error>, <Warning>, and <Message> elements
                        case XMakeElements.error:
                        case XMakeElements.warning:
                        case XMakeElements.message:
                            ProjectErrorUtilities.VerifyThrowInvalidProject(false, childElement, "ErrorWarningMessageNotSupported", childElement.Name);
                            break;

                        case XMakeElements.importGroup:
                            foreach (XmlElement importGroupChild in childElement.ChildNodes)
                            {
                                switch(importGroupChild.Name)
                                {
                                    case XMakeElements.import:
                                        ProcessImportElement(importGroupChild, projectDirectoryLocation, importedProject);
                                        break;
                                    default:
                                        ProjectXmlUtilities.ThrowProjectInvalidChildElement(importGroupChild);
                                        break;
                                }
                            }
                            break;

                        // Process the <Import> element.
                        case XMakeElements.import:
                            ProcessImportElement(childElement, projectDirectoryLocation, importedProject);
                            break;

                        default:
                            // We've encounted an unknown child element beneath <project>.
                            ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement);
                            break;
                    }
                }
            }
            finally
            {
                // Reset back to the original value
                Project.PerThreadProjectDirectory = currentPerThreadProjectDirectory;
            }
        }
示例#3
0
		void EvaluateBuildPropertyGroup (BuildPropertyGroup bpg)
		{
			project.PushThisFileProperty (bpg.DefinedInFileName);
			try {
				if (ConditionParser.ParseAndEvaluate (bpg.Condition, project))
					bpg.Evaluate ();
			} finally {
				project.PopThisFileProperty ();
			}
		}