diff options
Diffstat (limited to 'src')
5 files changed, 60 insertions, 20 deletions
diff --git a/src/wix/WixToolset.Converters/ConversionLab.cs b/src/wix/WixToolset.Converters/ConversionLab.cs index 903071f8..727ff1b1 100644 --- a/src/wix/WixToolset.Converters/ConversionLab.cs +++ b/src/wix/WixToolset.Converters/ConversionLab.cs | |||
| @@ -40,21 +40,58 @@ namespace WixToolset.Converters | |||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | public void RemoveTargetElement() | 43 | public void InsertElementBeforeTargetElement(XElement newElement) |
| 44 | { | ||
| 45 | var index = this.index - 1; | ||
| 46 | |||
| 47 | if (0 <= index | ||
| 48 | && this.siblingNodes[index] is XText leadingText | ||
| 49 | && String.IsNullOrWhiteSpace(leadingText.Value)) | ||
| 50 | { | ||
| 51 | this.siblingNodes.Insert(index, newElement); | ||
| 52 | this.siblingNodes.Insert(index, new XText(leadingText.Value)); | ||
| 53 | this.index += 2; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | private bool IsUniqueElement(XElement newElement) | ||
| 58 | { | ||
| 59 | foreach (XNode node in this.siblingNodes) | ||
| 60 | { | ||
| 61 | if (node is XElement element) | ||
| 62 | { | ||
| 63 | if (element.Name == newElement.Name) | ||
| 64 | { | ||
| 65 | return false; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | return true; | ||
| 71 | } | ||
| 72 | |||
| 73 | public void InsertUniqueElementBeforeTargetElement(XElement newElement) | ||
| 44 | { | 74 | { |
| 45 | if (this.index + 1 < this.siblingNodes.Count | 75 | if (this.IsUniqueElement(newElement)) |
| 46 | && this.siblingNodes[this.index + 1] is XText trailingText | ||
| 47 | && String.IsNullOrWhiteSpace(trailingText.Value)) | ||
| 48 | { | 76 | { |
| 49 | this.siblingNodes.RemoveAt(this.index + 1); | 77 | this.InsertElementBeforeTargetElement(newElement); |
| 50 | } | 78 | } |
| 79 | } | ||
| 80 | |||
| 81 | public void RemoveTargetElement() | ||
| 82 | { | ||
| 51 | this.siblingNodes.RemoveAt(this.index); | 83 | this.siblingNodes.RemoveAt(this.index); |
| 52 | if (0 < this.index | 84 | |
| 53 | && this.siblingNodes[this.index - 1] is XText leadingText | 85 | var index = this.index - 1; |
| 86 | |||
| 87 | if (0 <= index | ||
| 88 | && this.siblingNodes[index] is XText leadingText | ||
| 54 | && String.IsNullOrWhiteSpace(leadingText.Value)) | 89 | && String.IsNullOrWhiteSpace(leadingText.Value)) |
| 55 | { | 90 | { |
| 56 | this.siblingNodes.RemoveAt(this.index - 1); | 91 | this.siblingNodes.RemoveAt(index); |
| 57 | } | 92 | } |
| 93 | |||
| 94 | this.RemoveOrphanTextNodes(); | ||
| 58 | } | 95 | } |
| 59 | 96 | ||
| 60 | public void ReplaceTargetElement(XElement replacement) | 97 | public void ReplaceTargetElement(XElement replacement) |
diff --git a/src/wix/WixToolset.Converters/WixConverter.cs b/src/wix/WixToolset.Converters/WixConverter.cs index 7fc6314a..dc4a0bfa 100644 --- a/src/wix/WixToolset.Converters/WixConverter.cs +++ b/src/wix/WixToolset.Converters/WixConverter.cs | |||
| @@ -563,9 +563,7 @@ namespace WixToolset.Converters | |||
| 563 | else if (node is XElement element) | 563 | else if (node is XElement element) |
| 564 | { | 564 | { |
| 565 | this.ConvertElement(element); | 565 | this.ConvertElement(element); |
| 566 | |||
| 567 | var before = element.Nodes().ToList(); | 566 | var before = element.Nodes().ToList(); |
| 568 | |||
| 569 | this.ConvertNodes(before, level + 1); | 567 | this.ConvertNodes(before, level + 1); |
| 570 | 568 | ||
| 571 | // If any nodes were added during the processing of the children, | 569 | // If any nodes were added during the processing of the children, |
| @@ -1066,7 +1064,7 @@ namespace WixToolset.Converters | |||
| 1066 | { | 1064 | { |
| 1067 | xCondition.Remove(); | 1065 | xCondition.Remove(); |
| 1068 | element.Add(new XAttribute("Condition", text)); | 1066 | element.Add(new XAttribute("Condition", text)); |
| 1069 | lab.RemoveOrphanTextNodes(); | 1067 | lab. RemoveOrphanTextNodes(); |
| 1070 | lab.AddCommentsAsSiblings(comments); | 1068 | lab.AddCommentsAsSiblings(comments); |
| 1071 | } | 1069 | } |
| 1072 | } | 1070 | } |
| @@ -1280,6 +1278,7 @@ namespace WixToolset.Converters | |||
| 1280 | using (var lab = new ConversionLab(element)) | 1278 | using (var lab = new ConversionLab(element)) |
| 1281 | { | 1279 | { |
| 1282 | element.Add(new XAttribute("Condition", text)); | 1280 | element.Add(new XAttribute("Condition", text)); |
| 1281 | lab.RemoveOrphanTextNodes(); | ||
| 1283 | lab.AddCommentsAsSiblings(comments); | 1282 | lab.AddCommentsAsSiblings(comments); |
| 1284 | } | 1283 | } |
| 1285 | } | 1284 | } |
| @@ -1610,13 +1609,15 @@ namespace WixToolset.Converters | |||
| 1610 | if (!String.IsNullOrEmpty(newElementName) | 1609 | if (!String.IsNullOrEmpty(newElementName) |
| 1611 | && this.OnInformation(ConverterTestType.ReferencesReplaced, element, "UI, custom action, and property reference {0} has been replaced with strongly-typed element.", id)) | 1610 | && this.OnInformation(ConverterTestType.ReferencesReplaced, element, "UI, custom action, and property reference {0} has been replaced with strongly-typed element.", id)) |
| 1612 | { | 1611 | { |
| 1613 | this.XRoot.SetAttributeValue(XNamespace.Xmlns + newNamespaceName, newNamespace.NamespaceName); | 1612 | using (var lab = new ConversionLab(element)) |
| 1614 | |||
| 1615 | element.AddBeforeSelf(new XElement(newNamespace + newElementName)); | ||
| 1616 | |||
| 1617 | if (replace) | ||
| 1618 | { | 1613 | { |
| 1619 | element.Remove(); | 1614 | this.XRoot.SetAttributeValue(XNamespace.Xmlns + newNamespaceName, newNamespace.NamespaceName); |
| 1615 | lab.InsertUniqueElementBeforeTargetElement(new XElement(newNamespace + newElementName)); | ||
| 1616 | |||
| 1617 | if (replace) | ||
| 1618 | { | ||
| 1619 | lab.RemoveTargetElement(); | ||
| 1620 | } | ||
| 1620 | } | 1621 | } |
| 1621 | } | 1622 | } |
| 1622 | } | 1623 | } |
| @@ -2241,7 +2242,7 @@ namespace WixToolset.Converters | |||
| 2241 | element.Name = ns.GetName(element.Name.LocalName); | 2242 | element.Name = ns.GetName(element.Name.LocalName); |
| 2242 | } | 2243 | } |
| 2243 | 2244 | ||
| 2244 | // Remove all the attributes and add them back to with their namespace updated (as necessary). | 2245 | // Remove all the attributes and add them back with their namespace updated (as necessary). |
| 2245 | IEnumerable<XAttribute> attributes = element.Attributes().ToList(); | 2246 | IEnumerable<XAttribute> attributes = element.Attributes().ToList(); |
| 2246 | element.RemoveAttributes(); | 2247 | element.RemoveAttributes(); |
| 2247 | 2248 | ||
diff --git a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs index 24dee1c6..84e1b4c3 100644 --- a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs +++ b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs | |||
| @@ -187,6 +187,7 @@ namespace WixToolsetTest.Converters | |||
| 187 | var actualLines = UnformattedDocumentLines(document); | 187 | var actualLines = UnformattedDocumentLines(document); |
| 188 | WixAssert.CompareLineByLine(expected, actualLines); | 188 | WixAssert.CompareLineByLine(expected, actualLines); |
| 189 | } | 189 | } |
| 190 | |||
| 190 | [Fact] | 191 | [Fact] |
| 191 | public void FixPublishConditionWithComment() | 192 | public void FixPublishConditionWithComment() |
| 192 | { | 193 | { |
diff --git a/src/wix/test/WixToolsetTest.Converters/PrereqPackageFixture.cs b/src/wix/test/WixToolsetTest.Converters/PrereqPackageFixture.cs index 1f095e67..5d637f65 100644 --- a/src/wix/test/WixToolsetTest.Converters/PrereqPackageFixture.cs +++ b/src/wix/test/WixToolsetTest.Converters/PrereqPackageFixture.cs | |||
| @@ -29,7 +29,8 @@ namespace WixToolsetTest.Converters | |||
| 29 | var expected = new[] | 29 | var expected = new[] |
| 30 | { | 30 | { |
| 31 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:bal=\"http://wixtoolset.org/schemas/v4/wxs/bal\">", | 31 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:bal=\"http://wixtoolset.org/schemas/v4/wxs/bal\">", |
| 32 | " <Fragment><PackageGroup Id=\"NetFx452Web\">", | 32 | " <Fragment>", |
| 33 | " <PackageGroup Id=\"NetFx452Web\">", | ||
| 33 | " <ExePackage Id=\"NetFx452Web\" bal:PrereqPackage=\"yes\" bal:PrereqLicenseUrl=\"$(var.NetFx452EulaLink)\" />", | 34 | " <ExePackage Id=\"NetFx452Web\" bal:PrereqPackage=\"yes\" bal:PrereqLicenseUrl=\"$(var.NetFx452EulaLink)\" />", |
| 34 | " </PackageGroup>", | 35 | " </PackageGroup>", |
| 35 | " </Fragment>", | 36 | " </Fragment>", |
diff --git a/src/wix/test/WixToolsetTest.Converters/VSExtensionFixture.cs b/src/wix/test/WixToolsetTest.Converters/VSExtensionFixture.cs index 8f60cdf8..0cf8ae4b 100644 --- a/src/wix/test/WixToolsetTest.Converters/VSExtensionFixture.cs +++ b/src/wix/test/WixToolsetTest.Converters/VSExtensionFixture.cs | |||
| @@ -28,7 +28,7 @@ namespace WixToolsetTest.Converters | |||
| 28 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:vs=\"http://wixtoolset.org/schemas/v4/wxs/vs\">", | 28 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:vs=\"http://wixtoolset.org/schemas/v4/wxs/vs\">", |
| 29 | " <Fragment>", | 29 | " <Fragment>", |
| 30 | " <vs:FindVisualStudio />", | 30 | " <vs:FindVisualStudio />", |
| 31 | " <vs:FindVisualStudio /><PropertyRef Id=\"VS2022_BOOTSTRAPPER_PACKAGE_FOLDER\" />", | 31 | " <PropertyRef Id=\"VS2022_BOOTSTRAPPER_PACKAGE_FOLDER\" />", |
| 32 | " <CustomActionRef Id=\"VS2017Setup\" />", | 32 | " <CustomActionRef Id=\"VS2017Setup\" />", |
| 33 | " </Fragment>", | 33 | " </Fragment>", |
| 34 | "</Wix>" | 34 | "</Wix>" |
