Correctly convert LaunchConditions everywhere
Fixes 7264
Rob Mensching committed
Mar 9, 2023 at 00:25 UTC
3bc1056b69b420de75ce571c102b3b24c8cab390
2 files changed
+19
-28
src/wix/WixToolset.Converters/WixConverter.cs
+12
-17
@@ -289,7 +289,7 @@ namespace WixToolset.Converters
289
{ WixConverter.DirectoryRefElementName, this.ConvertDirectoryRefElement },
290
{ WixConverter.FeatureElementName, this.ConvertFeatureElement },
291
{ WixConverter.FileElementName, this.ConvertFileElement },
292
- { WixConverter.FragmentElementName, this.ConvertFragmentElement },
292
+ { WixConverter.ConditionElementName, this.ConvertLaunchConditionElement },
293
{ WixConverter.FirewallRemoteAddressElementName, this.ConvertFirewallRemoteAddressElement },
294
{ WixConverter.EmbeddedChainerElementName, this.ConvertEmbeddedChainerElement },
295
{ WixConverter.ErrorElementName, this.ConvertErrorElement },
@@ -1064,7 +1064,7 @@ namespace WixToolset.Converters
1064
{
1065
xCondition.Remove();
1066
element.Add(new XAttribute("Condition", text));
1067
- lab. RemoveOrphanTextNodes();
1067
+ lab.RemoveOrphanTextNodes();
1068
lab.AddCommentsAsSiblings(comments);
1069
}
1070
}
@@ -1205,25 +1205,20 @@ namespace WixToolset.Converters
1205
}
1206
}
1207
1208
- private void ConvertFragmentElement(XElement element)
1208
+ private void ConvertLaunchConditionElement(XElement element)
1209
{
1210
- var xConditions = element.Elements(ConditionElementName).ToList();
1210
+ var message = element.Attribute("Message")?.Value;
1211
1212
- foreach (var xCondition in xConditions)
1212
+ if (!String.IsNullOrEmpty(message) &&
1213
+ TryGetInnerText(element, out var text, out var comments) &&
1214
+ this.OnInformation(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", element.Name.LocalName))
1215
{
1214
- var message = xCondition.Attribute("Message")?.Value;
1215
-
1216
- if (!String.IsNullOrEmpty(message) &&
1217
- TryGetInnerText(xCondition, out var text, out var comments) &&
1218
- this.OnInformation(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", xCondition.Name.LocalName))
1216
+ using (var lab = new ConversionLab(element))
1217
{
1220
- using (var lab = new ConversionLab(xCondition))
1221
- {
1222
- lab.ReplaceTargetElement(new XElement(LaunchElementName,
1223
- new XAttribute("Condition", text),
1224
- new XAttribute("Message", message)));
1225
- lab.AddCommentsAsSiblings(comments);
1226
- }
1218
+ lab.ReplaceTargetElement(new XElement(LaunchElementName,
1219
+ new XAttribute("Condition", text),
1220
+ new XAttribute("Message", message)));
1221
+ lab.AddCommentsAsSiblings(comments);
1222
}
1223
}
1224
}
src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
+7
-11
@@ -382,19 +382,15 @@ namespace WixToolsetTest.Converters
382
var parse = String.Join(Environment.NewLine,
383
"<?xml version=\"1.0\" encoding=\"utf-16\"?>",
384
"<Include xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
385
- " <Fragment>",
386
- " <Condition Message='from wxi'>",
387
- " wxicondition",
388
- " </Condition>",
389
- " </Fragment>",
385
+ " <Condition Message='from wxi'>",
386
+ " wxicondition",
387
+ " </Condition>",
388
"</Include>");
389
390
var expected = new[]
391
{
392
"<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
395
- " <Fragment>",
396
- " <Launch Condition=\"wxicondition\" Message=\"from wxi\" />",
397
- " </Fragment>",
393
+ " <Launch Condition=\"wxicondition\" Message=\"from wxi\" />",
394
"</Include>"
395
};
396
@@ -485,7 +481,7 @@ namespace WixToolsetTest.Converters
481
}
482
483
[Fact]
488
- public void FixLaunchCondition()
484
+ public void FixLaunchConditionInFragment()
485
{
486
var parse = String.Join(Environment.NewLine,
487
"<?xml version=\"1.0\" encoding=\"utf-16\"?>",
@@ -569,7 +565,7 @@ namespace WixToolsetTest.Converters
565
"<?xml version=\"1.0\" encoding=\"utf-16\"?>",
566
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
567
" <Product>",
572
- " <Package />",
568
+ " <Package />",
569
" <Condition Message='Stop the install'>",
570
" 1<2",
571
" </Condition>",
@@ -583,7 +579,7 @@ namespace WixToolsetTest.Converters
579
{
580
"<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
581
" <Package Compressed=\"no\">",
586
- " ",
582
+ " ",
583
" <Launch Condition=\"1<2\" Message=\"Stop the install\" />",
584
" <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
585
" </Package>",