Preserve unconvertable Win64 attribute content
Rob Mensching committed
Feb 11, 2021 at 14:40 UTC
007e4dfe58293212180a617da25025e52677eee8
2 files changed
+35
-9
src/WixToolset.Converters/WixConverter.cs
+28
-8
@@ -636,8 +636,8 @@ namespace WixToolset.Converters
636
var win64 = element.Attribute("Win64");
637
if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
638
{
639
- var value = win64.Value;
640
- element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32"));
639
+ var value = this.UpdateWin64ValueToBitnessValue(win64);
640
+ element.Add(new XAttribute("Bitness", value));
641
win64.Remove();
642
}
643
}
@@ -755,8 +755,8 @@ namespace WixToolset.Converters
755
var win64 = element.Attribute("Win64");
756
if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
757
{
758
- var value = win64.Value;
759
- element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32"));
758
+ var value = this.UpdateWin64ValueToBitnessValue(win64);
759
+ element.Add(new XAttribute("Bitness", value));
760
win64.Remove();
761
}
762
}
@@ -1104,8 +1104,8 @@ namespace WixToolset.Converters
1104
var win64 = element.Attribute("Win64");
1105
if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
1106
{
1107
- var value = win64.Value;
1108
- element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32"));
1107
+ var value = this.UpdateWin64ValueToBitnessValue(win64);
1108
+ element.Add(new XAttribute("Bitness", value));
1109
win64.Remove();
1110
}
1111
}
@@ -1296,8 +1296,8 @@ namespace WixToolset.Converters
1296
var win64 = element.Attribute("Win64");
1297
if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
1298
{
1299
- var value = win64.Value;
1300
- element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32"));
1299
+ var value = this.UpdateWin64ValueToBitnessValue(win64);
1300
+ element.Add(new XAttribute("Bitness", value));
1301
win64.Remove();
1302
}
1303
@@ -1341,6 +1341,21 @@ namespace WixToolset.Converters
1341
}
1342
}
1343
1344
+ private string UpdateWin64ValueToBitnessValue(XAttribute xWin64Attribute)
1345
+ {
1346
+ var value = xWin64Attribute.Value ?? String.Empty;
1347
+ switch (value)
1348
+ {
1349
+ case "yes":
1350
+ return "always64";
1351
+ case "no":
1352
+ return "always32";
1353
+ default:
1354
+ this.OnError(ConverterTestType.Win64AttributeRenameCannotBeAutomatic, xWin64Attribute, "Breaking change: The Win64 attribute's value '{0}' cannot be converted automatically to the new Bitness attribute.", value);
1355
+ return value;
1356
+ }
1357
+ }
1358
+
1359
private IEnumerable<ConverterTestType> YieldConverterTypes(IEnumerable<string> types)
1360
{
1361
if (null != types)
@@ -1795,6 +1810,11 @@ namespace WixToolset.Converters
1810
/// The Win64 attribute has been renamed. Use the Bitness attribute instead.
1811
/// </summary>
1812
Win64AttributeRenamed,
1813
+
1814
+ /// <summary>
1815
+ /// Breaking change: The Win64 attribute's value '{0}' cannot be converted automatically to the new Bitness attribute.
1816
+ /// </summary>
1817
+ Win64AttributeRenameCannotBeAutomatic,
1818
}
1819
}
1820
}
src/test/WixToolsetTest.Converters/BitnessFixture.cs
+7
-1
@@ -27,6 +27,9 @@ namespace WixToolsetTest.Converters
27
" <Component Win64='yes'>",
28
" <File Source='64bit.exe' />",
29
" </Component>",
30
+ " <Component Win64='$(var.Win64)'>",
31
+ " <File Source='unconvert.exe' />",
32
+ " </Component>",
33
" </Fragment>",
34
"</Wix>");
35
@@ -43,6 +46,9 @@ namespace WixToolsetTest.Converters
46
" <Component Bitness=\"always64\">",
47
" <File Id=\"_64bit.exe\" Source=\"64bit.exe\" />",
48
" </Component>",
49
+ " <Component Bitness=\"$(var.Win64)\">",
50
+ " <File Id=\"unconvert.exe\" Source=\"unconvert.exe\" />",
51
+ " </Component>",
52
" </Fragment>",
53
"</Wix>"
54
};
@@ -53,7 +59,7 @@ namespace WixToolsetTest.Converters
59
var converter = new WixConverter(messaging, 2, null, null);
60
61
var errors = converter.ConvertDocument(document);
56
- Assert.Equal(7, errors);
62
+ Assert.Equal(10, errors);
63
64
var actualLines = UnformattedDocumentLines(document);
65
WixAssert.CompareLineByLine(expected, actualLines);