public MSBuildUsing(Project project, ProjectUsingTaskElement pute) { FileInfo f = new FileInfo(pute.TaskName); this.Name = f.Name; this.AssemblyFile = pute.AssemblyFile; this.TaskFactory = pute.TaskFactory; this.Source = project.ExpandString(pute.AssemblyFile); }
/// <summary> /// Verify the parent is a usingTaskElement and that the taskFactory attribute is set /// </summary> private static void VerifyCorrectParent(ProjectElementContainer parent) { ProjectUsingTaskElement parentUsingTask = parent as ProjectUsingTaskElement; ErrorUtilities.VerifyThrowInvalidOperation(parentUsingTask != null, "OM_CannotAcceptParent"); // Now since there is not goign to be a TaskElement on the using task we need to validate and make sure there is a TaskFactory attribute on the parent element and // that it is not empty if (parentUsingTask.TaskFactory.Length == 0) { ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(parent.XmlElement, "TaskFactory"); } // UNDONE: Do check to make sure the parameter group is the first child }
/// <summary> /// Initialize a parented ProjectUsingTaskBodyElement /// </summary> internal ProjectUsingTaskBodyElement(XmlElementWithLocation xmlElement, ProjectUsingTaskElement parent, ProjectRootElement containingProject) : base(xmlElement, parent, containingProject) { ErrorUtilities.VerifyThrowArgumentNull(parent, nameof(parent)); VerifyCorrectParent(parent); }
/// <summary> /// Parse a ProjectUsingTaskElement /// </summary> private ProjectUsingTaskElement ParseProjectUsingTaskElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTask); ProjectErrorUtilities.VerifyThrowInvalidProject(element.GetAttribute(XMakeAttributes.taskName).Length > 0, element.Location, "ProjectTaskNameEmpty"); string assemblyName = element.GetAttribute(XMakeAttributes.assemblyName); string assemblyFile = element.GetAttribute(XMakeAttributes.assemblyFile); ProjectErrorUtilities.VerifyThrowInvalidProject ( ((assemblyName.Length > 0) ^ (assemblyFile.Length > 0)), element.Location, "UsingTaskAssemblySpecification", XMakeElements.usingTask, XMakeAttributes.assemblyName, XMakeAttributes.assemblyFile ); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyName); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyFile); ProjectUsingTaskElement usingTask = new ProjectUsingTaskElement(element, _project, _project); bool foundTaskElement = false; bool foundParameterGroup = false; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; string childElementName = childElement.Name; switch (childElementName) { case XMakeElements.usingTaskParameterGroup: if (foundParameterGroup) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskParameterGroupElement(childElement, usingTask); foundParameterGroup = true; break; case XMakeElements.usingTaskBody: if (foundTaskElement) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskBodyElement(childElement, usingTask); foundTaskElement = true; break; default: ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, element.Name, element.Location); break; } usingTask.AppendParentedChildNoChecks(child); } return(usingTask); }
/// <summary> /// Parse a UsingTaskBodyElement from the element /// </summary> private ProjectUsingTaskBodyElement ParseUsingTaskBodyElement(XmlElementWithLocation element, ProjectUsingTaskElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTaskBody); XmlUtilities.VerifyThrowProjectValidElementName(element); return(new ProjectUsingTaskBodyElement(element, parent, _project)); }
/// <summary> /// Parse a ProjectUsingTaskElement /// </summary> private ProjectUsingTaskElement ParseProjectUsingTaskElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTask); ProjectErrorUtilities.VerifyThrowInvalidProject(element.GetAttribute(XMakeAttributes.taskName).Length > 0, element.Location, "ProjectTaskNameEmpty"); string assemblyName = element.GetAttribute(XMakeAttributes.assemblyName); string assemblyFile = element.GetAttribute(XMakeAttributes.assemblyFile); ProjectErrorUtilities.VerifyThrowInvalidProject ( ((assemblyName.Length > 0) ^ (assemblyFile.Length > 0)), element.Location, "UsingTaskAssemblySpecification", XMakeElements.usingTask, XMakeAttributes.assemblyName, XMakeAttributes.assemblyFile ); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyName); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyFile); ProjectUsingTaskElement usingTask = new ProjectUsingTaskElement(element, _project, _project); bool foundTaskElement = false; bool foundParameterGroup = false; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; string childElementName = childElement.Name; switch (childElementName) { case XMakeElements.usingTaskParameterGroup: if (foundParameterGroup) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskParameterGroupElement(childElement, usingTask); foundParameterGroup = true; break; case XMakeElements.usingTaskBody: if (foundTaskElement) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskBodyElement(childElement, usingTask); foundTaskElement = true; break; default: ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, element.Name, element.Location); break; } usingTask.AppendParentedChildNoChecks(child); } return usingTask; }
/// <summary> /// Parse a UsingTaskBodyElement from the element /// </summary> private ProjectUsingTaskBodyElement ParseUsingTaskBodyElement(XmlElementWithLocation element, ProjectUsingTaskElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTaskBody); XmlUtilities.VerifyThrowProjectValidElementName(element); return new ProjectUsingTaskBodyElement(element, parent, _project); }
/// <summary> /// Creates an unparented ProjectUsingTaskElement, wrapping an unparented XmlElement. /// Validates the parameters. /// Exactly one of assembly file and assembly name must have a value. /// Caller should then ensure the element is added to a parent /// </summary> internal static ProjectUsingTaskElement CreateDisconnected(string taskName, string assemblyFile, string assemblyName, string runtime, string architecture, ProjectRootElement containingProject) { ErrorUtilities.VerifyThrowArgument ( (String.IsNullOrEmpty(assemblyFile) ^ String.IsNullOrEmpty(assemblyName)), "OM_EitherAttributeButNotBoth", XMakeElements.usingTask, XMakeAttributes.assemblyFile, XMakeAttributes.assemblyName ); XmlElementWithLocation element = containingProject.CreateElement(XMakeElements.usingTask); ProjectUsingTaskElement usingTask = new ProjectUsingTaskElement(element, containingProject); usingTask.TaskName = taskName; usingTask.Runtime = runtime; usingTask.Architecture = architecture; if (!String.IsNullOrEmpty(assemblyFile)) { usingTask.AssemblyFile = assemblyFile; } else { usingTask.AssemblyName = assemblyName; } return usingTask; }
/// <summary> /// Verify the attributes are removed from the xml when string.empty and null are passed in /// </summary> private static void VerifyAttributesRemoved(ProjectUsingTaskElement usingTask, string value) { Assert.True(usingTask.ContainingProject.RawXml.Contains("TaskFactory")); usingTask.TaskFactory = value; Assert.False(usingTask.ContainingProject.RawXml.Contains("TaskFactory")); }
/// <summary> /// Initialize a parented ProjectUsingTaskBodyElement /// </summary> internal ProjectUsingTaskBodyElement(XmlElementWithLocation xmlElement, ProjectUsingTaskElement parent, ProjectRootElement containingProject) : base(xmlElement, parent, containingProject) { ErrorUtilities.VerifyThrowArgumentNull(parent, "parent"); VerifyCorrectParent(parent); }