Skip to content

Commit 79096b2

Browse files
committed
Magicked files in modules need complex references.
Magic files (naked `File`s and `Files`) that are direct children of a `Module` need complex references from the generated component to that module, to ensure that they're wired up correctly as module components. Fixes wixtoolset/issues#8860
1 parent 172d144 commit 79096b2

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

src/api/wix/WixToolset.Data/Symbols/HarvestFilesSymbol.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static partial class SymbolDefinitions
1616
new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.ComplexReferenceParentType), IntermediateFieldType.String),
1717
new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.ParentId), IntermediateFieldType.String),
1818
new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.SourcePath), IntermediateFieldType.String),
19+
new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.ModuleLanguage), IntermediateFieldType.String),
1920
},
2021
typeof(HarvestFilesSymbol));
2122
}
@@ -31,6 +32,7 @@ public enum HarvestFilesSymbolFields
3132
ComplexReferenceParentType,
3233
ParentId,
3334
SourcePath,
35+
ModuleLanguage,
3436
}
3537

3638
public class HarvestFilesSymbol : IntermediateSymbol
@@ -80,5 +82,11 @@ public string SourcePath
8082
get => (string)this.Fields[(int)HarvestFilesSymbolFields.SourcePath];
8183
set => this.Set((int)HarvestFilesSymbolFields.SourcePath, value);
8284
}
85+
86+
public string ModuleLanguage
87+
{
88+
get => (string)this.Fields[(int)HarvestFilesSymbolFields.ModuleLanguage];
89+
set => this.Set((int)HarvestFilesSymbolFields.ModuleLanguage, value);
90+
}
8391
}
8492
}

src/wix/WixToolset.Core/Compiler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,12 @@ private void ParseNakedFileElement(XElement node, ComplexReferenceParentType par
56895689

56905690
this.ParseFileElementChildren(node, fileSymbol, keyPath, win64);
56915691

5692-
if (ComplexReferenceParentType.Unknown != parentType && null != parentId) // if parent was provided, add a complex reference to that.
5692+
// if this is a module, automatically add this component to the references to ensure it gets in the ModuleComponents table
5693+
if (this.compilingModule)
5694+
{
5695+
this.Core.CreateComplexReference(sourceLineNumbers, ComplexReferenceParentType.Module, this.activeName, this.activeLanguage, ComplexReferenceChildType.Component, fileSymbol.Id.Id, false);
5696+
}
5697+
else if (ComplexReferenceParentType.Unknown != parentType && null != parentId) // if parent was provided, add a complex reference to that.
56935698
{
56945699
// If the naked file's component is defined directly under a feature, then mark the complex reference primary.
56955700
this.Core.CreateComplexReference(sourceLineNumbers, parentType, parentId, null, ComplexReferenceChildType.Component, fileSymbol.Id.Id, ComplexReferenceParentType.Feature == parentType);
@@ -5790,6 +5795,7 @@ private void ParseFilesElement(XElement node, ComplexReferenceParentType parentT
57905795
ComplexReferenceParentType = parentType.ToString(),
57915796
ParentId = parentId,
57925797
SourcePath = sourcePath,
5798+
ModuleLanguage = this.compilingModule ? this.activeLanguage : null,
57935799
});
57945800
}
57955801

src/wix/WixToolset.Core/HarvestFilesCommand.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se
107107
Win64 = this.Context.Platform == Platform.ARM64 || this.Context.Platform == Platform.X64,
108108
});
109109

110-
if (Enum.TryParse<ComplexReferenceParentType>(harvestFile.ComplexReferenceParentType, out var parentType)
110+
// if this is a module, automatically add this component to the references to ensure it gets in the ModuleComponents table
111+
if (!String.IsNullOrEmpty(harvestFile.ModuleLanguage))
112+
{
113+
this.ParseHelper.CreateComplexReference(section, harvestFile.SourceLineNumbers, ComplexReferenceParentType.Module, harvestFile.ParentId, harvestFile.ModuleLanguage, ComplexReferenceChildType.Component, id.Id, false);
114+
}
115+
else if (Enum.TryParse<ComplexReferenceParentType>(harvestFile.ComplexReferenceParentType, out var parentType)
111116
&& ComplexReferenceParentType.Unknown != parentType && null != harvestFile.ParentId)
112117
{
113-
// If the parent was provided, add a complex reference to that, and, if
118+
// If the parent was provided, add a complex reference to that, and, if
114119
// the Files is under a feature, then mark the complex reference primary.
115120
this.ParseHelper.CreateComplexReference(section, harvestFile.SourceLineNumbers, parentType, harvestFile.ParentId, null, ComplexReferenceChildType.Component, id.Id, ComplexReferenceParentType.Feature == parentType);
116121
}

src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace WixToolsetTest.CoreIntegration
99
using System.Linq;
1010
using WixInternal.Core.TestPackage;
1111
using WixInternal.TestSupport;
12+
using WixToolset.Data.WindowsInstaller;
1213
using Xunit;
1314

1415
public class HarvestFilesFixture
@@ -225,16 +226,34 @@ public void CanHarvestFilesInFragments()
225226
[Fact]
226227
public void CanHarvestFilesInModules()
227228
{
228-
var expected = new[]
229+
var expectedFilesAndTargetPaths = new[]
229230
{
230-
@"flsgrgAVAsCQ8tCCxfnbBNis66623c.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test1.txt",
231+
@"flsBvxG729t7hKBa4KOmfvNMPptZkM.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test4.txt",
231232
@"flsDBWSWjpVSU3Zs33bREsJa2ygSQM.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test2.txt",
232233
@"flsehdwEdXusUijRShuTszSxwf8joA.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test3.txt",
233-
@"flsBvxG729t7hKBa4KOmfvNMPptZkM.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test4.txt",
234+
@"flsgrgAVAsCQ8tCCxfnbBNis66623c.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\test1.txt",
234235
@"flskqOUVMfAE13k2h.ZkPhurwO4Y1c.E535B765_1019_4A4F_B3EA_AE28870E6D73=PFiles\MergeModule\notatest.txt",
235236
};
236237

237-
Build("Module.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected), isPackage: false);
238+
var expectedModuleComponents = new[]
239+
{
240+
"ModuleComponents:flsBvxG729t7hKBa4KOmfvNMPptZkM.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
241+
"ModuleComponents:flsDBWSWjpVSU3Zs33bREsJa2ygSQM.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
242+
"ModuleComponents:flsehdwEdXusUijRShuTszSxwf8joA.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
243+
"ModuleComponents:flsgrgAVAsCQ8tCCxfnbBNis66623c.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
244+
"ModuleComponents:flskqOUVMfAE13k2h.ZkPhurwO4Y1c.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
245+
};
246+
247+
Build("Module.wxs", (msiPath, _) => AssertModuleComponentsFileIdsAndTargetPaths(msiPath, expectedFilesAndTargetPaths, expectedModuleComponents), isMsi: false);
248+
249+
static void AssertModuleComponentsFileIdsAndTargetPaths(string msiPath, string[] expectedFilesAndTargetPaths, string[] expectedModuleComponents)
250+
{
251+
AssertFileIdsAndTargetPaths(msiPath, expectedFilesAndTargetPaths);
252+
253+
var query = Query.QueryDatabase(msiPath, new[] { "ModuleComponents" });
254+
255+
Assert.Equal(expectedModuleComponents, query);
256+
}
238257
}
239258

240259
[Fact]
@@ -325,7 +344,7 @@ private static void AssertFileIdsAndTargetPaths(string msiPath, string[] expecte
325344
Assert.Equal(sortedExpected, actual);
326345
}
327346

328-
private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool warningsAsErrors = true, params string[] additionalCommandLineArguments)
347+
private static void Build(string file, Action<string, WixRunnerResult> tester, bool isMsi = true, bool warningsAsErrors = true, params string[] additionalCommandLineArguments)
329348
{
330349
var folder = TestData.Get("TestData", "HarvestFiles");
331350

@@ -334,7 +353,7 @@ private static void Build(string file, Action<string, WixRunnerResult> tester, b
334353
var baseFolder = fs.GetFolder();
335354
var intermediateFolder = Path.Combine(baseFolder, "obj");
336355
var binFolder = Path.Combine(baseFolder, "bin");
337-
var msiPath = Path.Combine(binFolder, isPackage ? "test.msi" : "test.msm");
356+
var msiPath = Path.Combine(binFolder, isMsi ? "test.msi" : "test.msm");
338357

339358
var arguments = new List<string>()
340359
{

src/wix/test/WixToolsetTest.CoreIntegration/NakedFileFixture.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace WixToolsetTest.CoreIntegration
44
{
5+
using System.Collections.Generic;
56
using System.Data;
67
using System.IO;
78
using System.Linq;
@@ -82,6 +83,14 @@ public void CanBuildNakedFilesInModule()
8283
var rows = BuildAndQueryComponentAndFileTables("Module.wxs", isPackage: false);
8384

8485
AssertFileComponentIds(2, rows);
86+
87+
var expectedModuleComponents = new[]
88+
{
89+
"ModuleComponents:FILE1.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
90+
"ModuleComponents:FILE2.E535B765_1019_4A4F_B3EA_AE28870E6D73\tMergeModule.E535B765_1019_4A4F_B3EA_AE28870E6D73\t1033",
91+
};
92+
93+
Assert.Equal(expectedModuleComponents, rows.Where(row => row.StartsWith("ModuleComponents:")));
8594
}
8695

8796
[Fact]
@@ -215,7 +224,14 @@ private static string[] BuildAndQueryComponentAndFileTables(string file, bool is
215224
{
216225
result.AssertSuccess();
217226

218-
return Query.QueryDatabase(msiPath, new[] { "Component", "File" })
227+
var tables = new List<string> { "Component", "File" };
228+
229+
if (!isPackage)
230+
{
231+
tables.Add("ModuleComponents");
232+
}
233+
234+
return Query.QueryDatabase(msiPath, tables.ToArray())
219235
.OrderBy(s => s)
220236
.ToArray();
221237
}

0 commit comments

Comments
 (0)