Correctly detect wix4 for better conversions
Rob Mensching committed
Jun 27, 2020 at 22:55 UTC
c8e5b2b045b35bd6e5b8b2021a3173df16500887
3 files changed
+69
-11
src/WixToolset.Converters/WixConverter.cs
+14
-9
@@ -24,6 +24,7 @@ namespace WixToolset.Converters
24
25
private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n".
26
private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs";
27
+ private static readonly XNamespace Wix3Namespace = "http://schemas.microsoft.com/wix/2006/wi";
28
private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util";
29
30
private static readonly XName AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence";
@@ -68,7 +69,11 @@ namespace WixToolset.Converters
69
private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig";
70
private static readonly XName CustomActionElementName = WixNamespace + "CustomAction";
71
private static readonly XName PropertyElementName = WixNamespace + "Property";
72
+ private static readonly XName Wix4ElementName = WixNamespace + "Wix";
73
+ private static readonly XName Wix3ElementName = Wix3Namespace + "Wix";
74
private static readonly XName WixElementWithoutNamespaceName = XNamespace.None + "Wix";
75
+ private static readonly XName Include4ElementName = WixNamespace + "Include";
76
+ private static readonly XName Include3ElementName = Wix3Namespace + "Include";
77
private static readonly XName IncludeElementWithoutNamespaceName = XNamespace.None + "Include";
78
79
private static readonly Dictionary<string, XNamespace> OldToNewNamespaceMapping = new Dictionary<string, XNamespace>()
@@ -343,17 +348,17 @@ namespace WixToolset.Converters
348
349
foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration))
350
{
346
- if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns))
351
+ if (element.Name == Wix3ElementName || element.Name == Include3ElementName)
352
{
348
- if (Wix3Namespaces.Contains(declaration.Value))
349
- {
350
- this.SourceVersion = 3;
351
- }
352
- else if (Wix4Namespaces.Contains(declaration.Value))
353
- {
354
- this.SourceVersion = 4;
355
- }
353
+ this.SourceVersion = 3;
354
+ }
355
+ else if (element.Name == Wix4ElementName || element.Name == Include4ElementName)
356
+ {
357
+ this.SourceVersion = 4;
358
+ }
359
360
+ if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns))
361
+ {
362
if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName))
363
{
364
deprecatedToUpdatedNamespaces.Add(declaration.Value, ns);
src/test/WixToolsetTest.Converters/ConverterFixture.cs
+2
-2
@@ -331,7 +331,7 @@ namespace WixToolsetTest.Converters
331
{
332
var parse = String.Join(Environment.NewLine,
333
"<?xml version='1.0' encoding='utf-8'?>",
334
- "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
334
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
335
" <File Source='path\\to\\foo.txt' />",
336
"</Wix>");
337
@@ -349,7 +349,7 @@ namespace WixToolsetTest.Converters
349
350
var actual = UnformattedDocumentString(document);
351
352
- Assert.Equal(2, errors);
352
+ Assert.Equal(3, errors);
353
Assert.Equal(expected, actual);
354
}
355
src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs
new
+53
@@ -0,0 +1,53 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolsetTest.Converters
4
+{
5
+ using System;
6
+ using System.Xml.Linq;
7
+ using WixToolset.Converters;
8
+ using WixToolsetTest.Converters.Mocks;
9
+ using Xunit;
10
+
11
+ public class Wix4ConversionFixture : BaseConverterFixture
12
+ {
13
+ [Fact]
14
+ public void DoesNotAddFileId()
15
+ {
16
+ var parse = String.Join(Environment.NewLine,
17
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
18
+ "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
19
+ " <Fragment>",
20
+ " <ComponentGroup Id='ProductComponents' Directory='INSTALLFOLDER'>",
21
+ " <Component>",
22
+ " <File Source='example.txt' />",
23
+ " </Component>",
24
+ " </ComponentGroup>",
25
+ " </Fragment>",
26
+ "</Wix>");
27
+
28
+ var expected = new[]
29
+ {
30
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
31
+ " <Fragment>",
32
+ " <ComponentGroup Id=\"ProductComponents\" Directory=\"INSTALLFOLDER\">",
33
+ " <Component>",
34
+ " <File Source=\"example.txt\" />",
35
+ " </Component>",
36
+ " </ComponentGroup>",
37
+ " </Fragment>",
38
+ "</Wix>"
39
+ };
40
+
41
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
42
+
43
+ var messaging = new MockMessaging();
44
+ var converter = new WixConverter(messaging, 2, null, null);
45
+
46
+ var errors = converter.ConvertDocument(document);
47
+ Assert.Equal(1, errors);
48
+
49
+ var actualLines = UnformattedDocumentLines(document);
50
+ CompareLineByLine(expected, actualLines);
51
+ }
52
+ }
53
+}