diff --git a/eng/Versions.props b/eng/Versions.props index 91ab29ccea6..dcfb8e665c7 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 17.2.0release + 17.2.1release 15.1.0.0 preview true diff --git a/src/Build.OM.UnitTests/Construction/ProjectItemGroupElement_tests.cs b/src/Build.OM.UnitTests/Construction/ProjectItemGroupElement_tests.cs index db06dd22a74..05fa6347ad6 100644 --- a/src/Build.OM.UnitTests/Construction/ProjectItemGroupElement_tests.cs +++ b/src/Build.OM.UnitTests/Construction/ProjectItemGroupElement_tests.cs @@ -5,7 +5,6 @@ using System.Xml; using Microsoft.Build.Construction; -using Shouldly; using Xunit; #nullable disable @@ -71,49 +70,6 @@ public void ReadItemGroupTwoItems() Assert.Equal("i2", items[1].Include); } - [Fact] - public void DeepCopyFromItemGroupWithMetadata() - { - string content = @" - - - - metadataValue - - - - - - - - - - - "; - - ProjectRootElement project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content))); - ProjectItemGroupElement group = (ProjectItemGroupElement)Helpers.GetFirst(project.Children); - - ProjectRootElement newProject = ProjectRootElement.Create(); - ProjectItemGroupElement newItemGroup = project.AddItemGroup(); - - newItemGroup.DeepCopyFrom(group); - - var items = Helpers.MakeList(newItemGroup.Items); - - items.Count.ShouldBe(2); - - items[0].Include.ShouldBe("i1"); - ProjectMetadataElement metadataElement = items[0].Metadata.ShouldHaveSingleItem(); - metadataElement.Name.ShouldBe("M"); - metadataElement.Value.ShouldBe("metadataValue"); - - items[1].Include.ShouldBe("i2"); - metadataElement = items[1].Metadata.ShouldHaveSingleItem(); - metadataElement.Name.ShouldBe("M"); - metadataElement.Value.ShouldBe(""); - } - /// /// Set the condition value /// diff --git a/src/Build/Construction/ProjectElementContainer.cs b/src/Build/Construction/ProjectElementContainer.cs index 5a2d0da07c9..3de6bee0c32 100644 --- a/src/Build/Construction/ProjectElementContainer.cs +++ b/src/Build/Construction/ProjectElementContainer.cs @@ -407,46 +407,13 @@ protected internal virtual ProjectElementContainer DeepClone(ProjectRootElement } else { - ProjectElement childClone = child.Clone(clone.ContainingProject); - clone.AppendChild(childClone); - if (childClone.XmlElement is not null) - { - AppendAttributesAndChildren(childClone.XmlElement, child.XmlElement); - } + clone.AppendChild(child.Clone(clone.ContainingProject)); } } return clone; } - private void AppendAttributesAndChildren(XmlNode appendTo, XmlNode appendFrom) - { - appendTo.RemoveAll(); - // Copy over the attributes from the template element. - if (appendFrom.Attributes is not null) - { - foreach (XmlAttribute attribute in appendFrom.Attributes) - { - XmlAttribute attr = appendTo.OwnerDocument.CreateAttribute(attribute.LocalName, attribute.NamespaceURI); - attr.Value = attribute.Value; - appendTo.Attributes.Append(attr); - } - } - - // If this element has pure text content, copy that over. - if (appendFrom.ChildNodes.Count == 1 && appendFrom.FirstChild.NodeType == XmlNodeType.Text) - { - appendTo.AppendChild(appendTo.OwnerDocument.CreateTextNode(appendFrom.FirstChild.Value)); - } - - foreach (XmlNode child in appendFrom.ChildNodes) - { - XmlNode childClone = appendTo.OwnerDocument.CreateNode(child.NodeType, child.Prefix, child.Name, child.NamespaceURI); - appendTo.AppendChild(childClone); - AppendAttributesAndChildren(childClone, child); - } - } - internal static ProjectElementContainer DeepClone(ProjectElementContainer xml, ProjectRootElement factory, ProjectElementContainer parent) { return xml.DeepClone(factory, parent);