public MSBuildItemDefinitionGroup(MSBuildBasedProject project, string condition) { ProjectRootElement root = project.MSBuildProjectFile; group = root.ItemDefinitionGroups.SingleOrDefault(item => item.Condition == condition); if (group == null) { group = root.CreateItemDefinitionGroupElement(); group.Condition = condition; root.AppendChild(group); } }
/// <summary> /// Pasre a ProjectItemDefinitionElement /// </summary> private ProjectItemDefinitionElement ParseProjectItemDefinitionXml(XmlElementWithLocation element, ProjectItemDefinitionGroupElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel); // Orcas inadvertently did not check for reserved item types (like "Choose") in item definitions, // as we do for item types in item groups. So we do not have a check here. // Although we could perhaps add one, as such item definitions couldn't be used // since no items can have the reserved itemType. ProjectItemDefinitionElement itemDefinition = new ProjectItemDefinitionElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, itemDefinition); itemDefinition.AppendParentedChildNoChecks(metadatum); } return(itemDefinition); }
/// <summary> /// Pasre a ProjectItemDefinitionElement /// </summary> private ProjectItemDefinitionElement ParseProjectItemDefinitionXml(XmlElementWithLocation element, ProjectItemDefinitionGroupElement parent) { // Orcas inadvertently did not check for reserved item types (like "Choose") in item definitions, // as we do for item types in item groups. So we do not have a check here. // Although we could perhaps add one, as such item definitions couldn't be used // since no items can have the reserved itemType. ProjectItemDefinitionElement itemDefinition = new ProjectItemDefinitionElement(element, parent, _project); foreach (XmlAttributeWithLocation attribute in element.Attributes) { CheckMetadataAsAttributeName(attribute.Name, out bool isKnownAttribute, out bool isValidMetadataNameInAttribute); if (!isKnownAttribute && !isValidMetadataNameInAttribute) { ProjectXmlUtilities.ThrowProjectInvalidAttribute(attribute); } else if (isValidMetadataNameInAttribute) { ProjectMetadataElement metadatum = _project.CreateMetadataElement(attribute.Name, attribute.Value); metadatum.ExpressedAsAttribute = true; metadatum.Parent = itemDefinition; itemDefinition.AppendParentedChildNoChecks(metadatum); } else if (!ValidAttributesOnlyConditionAndLabel.Contains(attribute.Name)) { ProjectXmlUtilities.ThrowProjectInvalidAttribute(attribute); } } foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, itemDefinition); itemDefinition.AppendParentedChildNoChecks(metadatum); } return(itemDefinition); }
/// <summary> /// Pasre a ProjectItemDefinitionElement /// </summary> private ProjectItemDefinitionElement ParseProjectItemDefinitionXml(XmlElementWithLocation element, ProjectItemDefinitionGroupElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel); // Orcas inadvertently did not check for reserved item types (like "Choose") in item definitions, // as we do for item types in item groups. So we do not have a check here. // Although we could perhaps add one, as such item definitions couldn't be used // since no items can have the reserved itemType. ProjectItemDefinitionElement itemDefinition = new ProjectItemDefinitionElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, itemDefinition); itemDefinition.AppendParentedChildNoChecks(metadatum); } return itemDefinition; }
/// <summary> /// Parse a ProjectItemDefinitionGroupElement /// </summary> private ProjectItemDefinitionGroupElement ParseProjectItemDefinitionGroupElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel); ProjectItemDefinitionGroupElement itemDefinitionGroup = new ProjectItemDefinitionGroupElement(element, _project, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectItemDefinitionElement itemDefinition = ParseProjectItemDefinitionXml(childElement, itemDefinitionGroup); itemDefinitionGroup.AppendParentedChildNoChecks(itemDefinition); } return itemDefinitionGroup; }
/// <summary> /// Initialize a ProjectItemDefinitionElement instance from a node read from a project file /// </summary> internal ProjectItemDefinitionElement(XmlElement xmlElement, ProjectItemDefinitionGroupElement parent, ProjectRootElement containingProject) : base(xmlElement, parent, containingProject) { ErrorUtilities.VerifyThrowArgumentNull(parent, "parent"); }
static void addItemDef(ProjectItemDefinitionGroupElement pidge, string toolName, bool isDebug, Blah3 blah3) { var avar = pidge.AddItemDefinition(toolName); if (blah3 != null) blah3(avar, isDebug); }
internal ProjectItemDefinitionElement LookupItemDefinition(ProjectItemDefinitionGroupElement parent, string itemType, string condition = null) { ProjectItemDefinitionElement itemDefinition = null; var label = Pivots.GetExpressionLabel(condition); if(string.IsNullOrEmpty(condition)) { itemDefinition = parent.ItemDefinitions.FirstOrDefault(each => itemType == each.ItemType && string.IsNullOrEmpty(each.Condition)); if(itemDefinition != null) { return itemDefinition; } return parent.AddItemDefinition(itemType); } var conditionExpression = Pivots.GetMSBuildCondition(Name, condition); itemDefinition = parent.ItemDefinitions.FirstOrDefault(each => itemType == each.ItemType && each.Condition == conditionExpression); if(itemDefinition != null) { return itemDefinition; } itemDefinition = parent.AddItemDefinition(itemType); itemDefinition.Label = label; itemDefinition.Condition = conditionExpression; return itemDefinition; }
/// <summary> /// Initialize a ProjectItemDefinitionElement instance from a node read from a project file /// </summary> internal ProjectItemDefinitionElement(XmlElement xmlElement, ProjectItemDefinitionGroupElement parent, ProjectRootElement containingProject) : base(xmlElement, parent, containingProject) { ErrorUtilities.VerifyThrowArgumentNull(parent, "parent"); }