Ejemplo n.º 1
0
        /// <summary>
        /// Parses the project into the ProjectRootElement
        /// </summary>
        private void Parse()
        {
            // XML guarantees exactly one root element
            XmlElementWithLocation element = _document.DocumentElement as XmlElementWithLocation;

            ProjectErrorUtilities.VerifyThrowInvalidProject(element != null, ElementLocation.Create(_document.FullPath), "NoRootProjectElement", XMakeElements.project);
            ProjectErrorUtilities.VerifyThrowInvalidProject(element.Name != XMakeElements.visualStudioProject, element.Location, "ProjectUpgradeNeeded", _project.FullPath);
            ProjectErrorUtilities.VerifyThrowInvalidProject(element.LocalName == XMakeElements.project, element.Location, "UnrecognizedElement", element.Name);

            // If a namespace was specified it must be the default MSBuild namespace.
            if (!ProjectXmlUtilities.VerifyValidProjectNamespace(element))
            {
                ProjectErrorUtilities.ThrowInvalidProject(element.Location, "ProjectMustBeInMSBuildXmlNamespace",
                                                          XMakeAttributes.defaultXmlNamespace);
            }
            else
            {
                _project.XmlNamespace = element.NamespaceURI;
            }

            // Historically, we allow any attribute on the Project element

            // The element wasn't available to the ProjectRootElement constructor so we have to set it now
            _project.SetProjectRootElementFromParser(element, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                switch (childElement.Name)
                {
                case XMakeElements.propertyGroup:
                    _project.AppendParentedChildNoChecks(ParseProjectPropertyGroupElement(childElement, _project));
                    break;

                case XMakeElements.itemGroup:
                    _project.AppendParentedChildNoChecks(ParseProjectItemGroupElement(childElement, _project));
                    break;

                case XMakeElements.importGroup:
                    _project.AppendParentedChildNoChecks(ParseProjectImportGroupElement(childElement, _project));
                    break;

                case XMakeElements.import:
                    _project.AppendParentedChildNoChecks(ParseProjectImportElement(childElement, _project));
                    break;

                case XMakeElements.usingTask:
                    _project.AppendParentedChildNoChecks(ParseProjectUsingTaskElement(childElement));
                    break;

                case XMakeElements.target:
                    _project.AppendParentedChildNoChecks(ParseProjectTargetElement(childElement));
                    break;

                case XMakeElements.itemDefinitionGroup:
                    _project.AppendParentedChildNoChecks(ParseProjectItemDefinitionGroupElement(childElement));
                    break;

                case XMakeElements.choose:
                    _project.AppendParentedChildNoChecks(ParseProjectChooseElement(childElement, _project, 0 /* nesting depth */));
                    break;

                case XMakeElements.projectExtensions:
                    _project.AppendParentedChildNoChecks(ParseProjectExtensionsElement(childElement));
                    break;

                case XMakeElements.sdk:
                    _project.AppendParentedChildNoChecks(ParseProjectSdkElement(childElement));
                    break;

                // Obsolete
                case XMakeElements.error:
                case XMakeElements.warning:
                case XMakeElements.message:
                    ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ErrorWarningMessageNotSupported", childElement.Name);
                    break;

                default:
                    ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, childElement.ParentNode.Name, childElement.Location);
                    break;
                }
            }
        }