Make Publish/@Condition truly optional
There is a change to the Core to add the condition back
Rob Mensching committed
Jul 1, 2020 at 00:10 UTC
181aa7076a5bdc4d554d29ec9f96dc923e40a6ed
2 files changed
+56
-1
src/WixToolset.Converters/WixConverter.cs
+10
-1
@@ -601,7 +601,16 @@ namespace WixToolset.Converters
601
}
602
}
603
604
- private void ConvertPublishElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition");
604
+ private void ConvertPublishElement(XElement element)
605
+ {
606
+ this.ConvertInnerTextToAttribute(element, "Condition");
607
+
608
+ var xCondition = element.Attribute("Condition");
609
+ if (xCondition?.Value == "1")
610
+ {
611
+ xCondition.Remove();
612
+ }
613
+ }
614
615
private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value");
616
src/test/WixToolsetTest.Converters/ConditionFixture.cs
+46
@@ -56,6 +56,52 @@ namespace WixToolsetTest.Converters
56
CompareLineByLine(expected, actualLines);
57
}
58
59
+ [Fact]
60
+ public void FixPublishCondition()
61
+ {
62
+ var parse = String.Join(Environment.NewLine,
63
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
64
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
65
+ " <Fragment>",
66
+ " <UI>",
67
+ " <Dialog Id='Dlg1'>",
68
+ " <Control Id='Control1'>",
69
+ " <Publish Value='abc'>1<2</Publish>",
70
+ " <Publish Value='gone'>1</Publish>",
71
+ " </Control>",
72
+ " </Dialog>",
73
+ " </UI>",
74
+ " </Fragment>",
75
+ "</Wix>");
76
+
77
+ var expected = new[]
78
+ {
79
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
80
+ " <Fragment>",
81
+ " <UI>",
82
+ " <Dialog Id=\"Dlg1\">",
83
+ " <Control Id=\"Control1\">",
84
+ " <Publish Value=\"abc\" Condition=\"1<2\" />",
85
+ " <Publish Value=\"gone\" />",
86
+ " </Control>",
87
+ " </Dialog>",
88
+ " </UI>",
89
+ " </Fragment>",
90
+ "</Wix>"
91
+ };
92
+
93
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
94
+
95
+ var messaging = new MockMessaging();
96
+ var converter = new WixConverter(messaging, 2, null, null);
97
+
98
+ var errors = converter.ConvertDocument(document);
99
+ Assert.Equal(4, errors);
100
+
101
+ var actualLines = UnformattedDocumentLines(document);
102
+ CompareLineByLine(expected, actualLines);
103
+ }
104
+
105
[Fact]
106
public void FixComponentCondition()
107
{