internal ProjectItem (Project project, ProjectItemElement xml, string evaluatedInclude) { this.project = project; this.xml = xml; if (project.ItemDefinitions.ContainsKey (ItemType)) foreach (var md in project.ItemDefinitions [ItemType].Metadata) metadata.Add (md); foreach (var md in xml.Metadata) metadata.Add (new ProjectMetadata (project, ItemType, metadata, m => metadata.Remove (m), md)); this.evaluated_include = evaluatedInclude; is_imported = project.ProjectCollection.OngoingImports.Any (); }
/// <summary> /// Convenience method that picks a location based on a heuristic: /// Adds a new item ordered by include. /// Metadata may be null, indicating no metadata. /// </summary> public ProjectItemElement AddItem(string itemType, string include, IEnumerable <KeyValuePair <string, string> > metadata) { ErrorUtilities.VerifyThrowArgumentLength(itemType, "itemType"); ErrorUtilities.VerifyThrowArgumentLength(include, "include"); // If there are no items, or it turns out that there are only items with // item types that sort earlier, then we should go after the last child ProjectElement reference = LastChild; foreach (ProjectItemElement item in Items) { // If it's the same item type, and if (MSBuildNameIgnoreCaseComparer.Default.Equals(itemType, item.ItemType)) { // the include sorts after us, if (String.Compare(include, item.Include, StringComparison.OrdinalIgnoreCase) < 0) { // then insert before it (ie. after the previous sibling) reference = item.PreviousSibling; break; } // Otherwise go to the next item continue; } // If it's an item type that sorts after us, if (String.Compare(itemType, item.ItemType, StringComparison.OrdinalIgnoreCase) < 0) { // then insert before it (ie. after the previous sibling) reference = item.PreviousSibling; break; } } ProjectItemElement newItem = ContainingProject.CreateItemElement(itemType, include); // If reference is null, this will prepend InsertAfterChild(newItem, reference); if (metadata != null) { foreach (KeyValuePair <string, string> metadatum in metadata) { newItem.AddMetadata(metadatum.Key, metadatum.Value); } } return(newItem); }
/// <summary> /// Parse a ProjectItemGroupElement /// </summary> private ProjectItemGroupElement ParseProjectItemGroupElement(XmlElementWithLocation element, ProjectElementContainer parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel); ProjectItemGroupElement itemGroup = new ProjectItemGroupElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectItemElement item = ParseProjectItemElement(childElement, itemGroup); itemGroup.AppendParentedChildNoChecks(item); } return(itemGroup); }
internal ProjectItemGroupTaskItemInstance (ProjectItemElement xml) { Condition = xml.Condition; Exclude = xml.Exclude; Include = xml.Include; ItemType = xml.ItemType; Metadata = xml.Metadata.Select (m => new ProjectItemGroupTaskMetadataInstance (m)).ToArray (); Remove = xml.Remove; KeepDuplicates = xml.KeepDuplicates; KeepMetadata = xml.KeepMetadata; RemoveMetadata = xml.RemoveMetadata; ConditionLocation = xml.ConditionLocation; ExcludeLocation = xml.ExcludeLocation; IncludeLocation = xml.IncludeLocation; Location = xml.Location; KeepDuplicatesLocation = xml.KeepDuplicatesLocation; RemoveLocation = xml.RemoveLocation; RemoveMetadataLocation = xml.RemoveMetadataLocation; }
private AssemblyReference ReadAssemblyReferenceItem(ProjectItemElement element) { var reference = new AssemblyReference(element.Include); if (element.HasMetadata) { foreach (var metadata in element.Metadata) { switch (metadata.Name) { case "SpecificVersion": reference.SpecificVersion = bool.Parse(metadata.Value); break; case "HintPath": reference.HintPath = metadata.Value; break; default: throw new FormatException(string.Format("Invalid or unsupported metadata '{0}'.", metadata.Name)); } } } return reference; }
/// <summary> /// Parse a ProjectItemElement /// </summary> private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem); bool belowTarget = parent.Parent is ProjectTargetElement; string itemType = element.Name; string include = element.GetAttribute(XMakeAttributes.include); string exclude = element.GetAttribute(XMakeAttributes.exclude); string remove = element.GetAttribute(XMakeAttributes.remove); // Remove must be missing, unless inside a target and Include is missing ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute((remove.Length == 0 || (belowTarget && include.Length == 0)), (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove]); // Include must be present, unless inside a target ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || belowTarget, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); // Exclude must be missing, unless Include exists ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]); // If we have an Include attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); XmlUtilities.VerifyThrowProjectValidElementName(element); ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType); ProjectItemElement item = new ProjectItemElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item); item.AppendParentedChildNoChecks(metadatum); } return(item); }
/// <summary> /// Parse a ProjectItemElement /// </summary> private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem); bool belowTarget = parent.Parent is ProjectTargetElement; string itemType = element.Name; string include = element.GetAttribute(XMakeAttributes.include); string exclude = element.GetAttribute(XMakeAttributes.exclude); string remove = element.GetAttribute(XMakeAttributes.remove); string update = element.GetAttribute(XMakeAttributes.update); var exclusiveItemOperation = ""; int exclusiveAttributeCount = 0; if (element.HasAttribute(XMakeAttributes.include)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.include; } if (element.HasAttribute(XMakeAttributes.remove)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.remove; } if (element.HasAttribute(XMakeAttributes.update)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.update; } // At most one of the include, remove, or update attributes may be specified if (exclusiveAttributeCount > 1) { XmlAttributeWithLocation errorAttribute = remove.Length > 0 ? (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove] : (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.update]; ProjectErrorUtilities.ThrowInvalidProject(errorAttribute.Location, "InvalidAttributeExclusive"); } // Include, remove, or update must be present unless inside a target ProjectErrorUtilities.VerifyThrowInvalidProject(exclusiveAttributeCount == 1 || belowTarget, element.Location, "MissingRequiredAttribute", exclusiveItemOperation, itemType); // Exclude must be missing, unless Include exists ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]); // If we have an Include attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); // If we have a Remove attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(remove.Length > 0 || element.Attributes[XMakeAttributes.remove] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.remove, itemType); // If we have an Update attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(update.Length > 0 || element.Attributes[XMakeAttributes.update] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.update, itemType); XmlUtilities.VerifyThrowProjectValidElementName(element); ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType); ProjectItemElement item = new ProjectItemElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item); item.AppendParentedChildNoChecks(metadatum); } return item; }
internal ProjectItem (ProjectItemElement xml) { Xml = xml; }
private bool IsPotentialSourceFile(ProjectItemElement item) { var nonFileTypes = GetNonFileTypesList(); string include = item.Include ?? string.Empty; return !item.ItemType.StartsWith("_") && !item.ItemType.StartsWith("ls-") && !nonFileTypes.Contains(item.ItemType) && !include.EndsWith(@"/") && !include.EndsWith(@"\"); }
private static bool IsGuidValue(ProjectItemElement e) { Guid g; foreach (var i in (e.Include?.Split('/', '\\')).MaybeEnumerate()) { if (Guid.TryParse(i?.Trim() ?? "", out g)) { return true; } } return false; }
internal BuildItemProxy(object bi) { instance = ((Microsoft.Build.Evaluation.ProjectItem)bi).Xml; }
internal BuildItemProxy(ProjectItemElement instance) { this.instance = instance; }
private ProjectFileEntry ReadProjectFileEntryItem(ProjectItemElement element) { var entry = new ProjectFileEntry(new FilePath(this.ProjectDirectory, element.Include)); foreach (var metadata in element.Metadata) { if (metadata.Name == "DependentUpon") { entry.Dependencies.Add(metadata.Value); } } entry.ParentProject = this; return entry; }
/// <summary> /// Creates an unparented ProjectItemElement, wrapping an unparented XmlElement. /// Caller should then ensure the element is added to a parent. /// </summary> internal static ProjectItemElement CreateDisconnected(string itemType, ProjectRootElement containingProject) { XmlUtilities.VerifyThrowArgumentValidElementName(itemType); ErrorUtilities.VerifyThrowArgument(XMakeElements.IllegalItemPropertyNames[itemType] == null, "CannotModifyReservedItem", itemType); XmlElementWithLocation element = containingProject.CreateElement(itemType); ProjectItemElement item = new ProjectItemElement(element, containingProject); return item; }
public ProjectTaskItem (ProjectItemElement item, string evaluatedIncludePart) { this.item = item; this.evaluated_include_part = WindowsCompatibilityExtensions.NormalizeFilePath (evaluatedIncludePart); }
/// <summary> /// Parse a ProjectItemElement /// </summary> private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent) { bool belowTarget = parent.Parent is ProjectTargetElement; string itemType = element.Name; string include = element.GetAttribute(XMakeAttributes.include); string exclude = element.GetAttribute(XMakeAttributes.exclude); string remove = element.GetAttribute(XMakeAttributes.remove); string update = element.GetAttribute(XMakeAttributes.update); var exclusiveItemOperation = ""; int exclusiveAttributeCount = 0; if (element.HasAttribute(XMakeAttributes.include)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.include; } if (element.HasAttribute(XMakeAttributes.remove)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.remove; } if (element.HasAttribute(XMakeAttributes.update)) { exclusiveAttributeCount++; exclusiveItemOperation = XMakeAttributes.update; } // At most one of the include, remove, or update attributes may be specified if (exclusiveAttributeCount > 1) { XmlAttributeWithLocation errorAttribute = remove.Length > 0 ? (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove] : (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.update]; ProjectErrorUtilities.ThrowInvalidProject(errorAttribute.Location, "InvalidAttributeExclusive"); } // Include, remove, or update must be present unless inside a target ProjectErrorUtilities.VerifyThrowInvalidProject(exclusiveAttributeCount == 1 || belowTarget, element.Location, "IncludeRemoveOrUpdate", exclusiveItemOperation, itemType); // Exclude must be missing, unless Include exists ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]); // If we have an Include attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); // If we have a Remove attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(remove.Length > 0 || element.Attributes[XMakeAttributes.remove] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.remove, itemType); // If we have an Update attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(update.Length > 0 || element.Attributes[XMakeAttributes.update] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.update, itemType); XmlUtilities.VerifyThrowProjectValidElementName(element); ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType); ProjectItemElement item = new ProjectItemElement(element, parent, _project); foreach (XmlAttributeWithLocation attribute in element.Attributes) { bool isKnownAttribute; bool isValidMetadataNameInAttribute; CheckMetadataAsAttributeName(attribute.Name, out isKnownAttribute, out isValidMetadataNameInAttribute); if (!isKnownAttribute && !isValidMetadataNameInAttribute) { ProjectXmlUtilities.ThrowProjectInvalidAttribute(attribute); } else if (isValidMetadataNameInAttribute) { ProjectMetadataElement metadatum = _project.CreateMetadataElement(attribute.Name, attribute.Value); metadatum.ExpressedAsAttribute = true; metadatum.Parent = item; item.AppendParentedChildNoChecks(metadatum); } } foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item); item.AppendParentedChildNoChecks(metadatum); } return(item); }
/// <summary> /// Parse a ProjectItemElement /// </summary> private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem); bool belowTarget = parent.Parent is ProjectTargetElement; string itemType = element.Name; string include = element.GetAttribute(XMakeAttributes.include); string exclude = element.GetAttribute(XMakeAttributes.exclude); string remove = element.GetAttribute(XMakeAttributes.remove); // Remove must be missing, unless inside a target and Include is missing ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute((remove.Length == 0 || (belowTarget && include.Length == 0)), (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove]); // Include must be present, unless inside a target ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || belowTarget, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); // Exclude must be missing, unless Include exists ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]); // If we have an Include attribute at all, it must have non-zero length ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType); XmlUtilities.VerifyThrowProjectValidElementName(element); ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType); ProjectItemElement item = new ProjectItemElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item); item.AppendParentedChildNoChecks(metadatum); } return item; }