Fix feature/component mapping verification
Rob Mensching committed
Feb 3, 2022 at 07:36 UTC
7d15b1bc97cdd9933ca43a6b16b84a81b22c3457
3 files changed
+69
-7
src/wix/WixToolset.Core/Linker.cs
+5
-7
@@ -156,11 +156,11 @@ namespace WixToolset.Core
156
}
157
158
// Display an error message for Components that were not referenced by a Feature.
159
- foreach (var symbolWithSection in resolve.ReferencedSymbolWithSections.Where(s => s.Symbol.Definition.Type == SymbolDefinitionType.Component))
159
+ foreach (var component in sections.SelectMany(s => s.Symbols.Where(y => y.Definition.Type == SymbolDefinitionType.Component)))
160
{
161
- if (!referencedComponents.Contains(symbolWithSection.Name))
161
+ if (!referencedComponents.Contains(component.Id.Id))
162
{
163
- this.Messaging.Write(ErrorMessages.OrphanedComponent(symbolWithSection.Symbol.SourceLineNumbers, symbolWithSection.Symbol.Id.Id));
163
+ this.Messaging.Write(ErrorMessages.OrphanedComponent(component.SourceLineNumbers, component.Id.Id));
164
}
165
}
166
@@ -451,8 +451,7 @@ namespace WixToolset.Core
451
});
452
453
// index the component for finding orphaned records
454
- var symbolName = String.Concat("Component:", wixComplexReferenceRow.Child);
455
- referencedComponents.Add(symbolName);
454
+ referencedComponents.Add(wixComplexReferenceRow.Child);
455
456
break;
457
@@ -521,8 +520,7 @@ namespace WixToolset.Core
520
}
521
522
// index the component for finding orphaned records
524
- var componentSymbolName = String.Concat("Component:", wixComplexReferenceRow.Child);
525
- referencedComponents.Add(componentSymbolName);
523
+ referencedComponents.Add(wixComplexReferenceRow.Child);
524
525
break;
526
src/wix/test/WixToolsetTest.CoreIntegration/FeatureFixture.cs
new
+43
@@ -0,0 +1,43 @@
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.CoreIntegration
4
+{
5
+ using System;
6
+ using System.IO;
7
+ using System.Linq;
8
+ using WixBuildTools.TestSupport;
9
+ using WixToolset.Core.TestPackage;
10
+ using WixToolset.Data;
11
+ using Xunit;
12
+
13
+ public class FeatureFixture
14
+ {
15
+ [Fact]
16
+ public void CanDetectMissingFeatureComponentMapping()
17
+ {
18
+ var folder = TestData.Get(@"TestData");
19
+
20
+ using (var fs = new DisposableFileSystem())
21
+ {
22
+ var baseFolder = fs.GetFolder();
23
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
24
+ var msiPath = Path.Combine(baseFolder, @"bin\test.msi");
25
+
26
+ var result = WixRunner.Execute(new[]
27
+ {
28
+ "build",
29
+ Path.Combine(folder, "Feature", "PackageMissingFeatureComponentMapping.wxs"),
30
+ "-bindpath", Path.Combine(folder, "SingleFile", "data"),
31
+ "-intermediateFolder", intermediateFolder,
32
+ "-o", msiPath
33
+ });
34
+
35
+ var errors = result.Messages.Where(m => m.Level == MessageLevel.Error);
36
+ Assert.Equal(new[]
37
+ {
38
+ 267
39
+ }, errors.Select(e => e.Id).ToArray());
40
+ }
41
+ }
42
+ }
43
+}
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Feature/PackageMissingFeatureComponentMapping.wxs
new
+21
@@ -0,0 +1,21 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Name="PackageMissingFeatureComponentMapping" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="12E4699F-E774-4D05-8A01-5BDD41BBA127">
3
+ <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
4
+
5
+ <StandardDirectory Id="ProgramFiles6432Folder">
6
+ <Directory Id="INSTALLFOLDER" Name="PackageMissingFeatureComponentMapping">
7
+ <Directory Name="NotMapped">
8
+ <Component>
9
+ <File Source="test.txt" />
10
+ </Component>
11
+ </Directory>
12
+ </Directory>
13
+ </StandardDirectory>
14
+
15
+ <Feature Id="MissingComponentFeature" Title="Feature is Missing a ComponentRef">
16
+ <Component Directory="INSTALLFOLDER">
17
+ <File Source="test.txt" />
18
+ </Component>
19
+ </Feature>
20
+ </Package>
21
+</Wix>