Use an unnamed bindpath as a default root for...
...harvesting files (as documented). - Fixes https://github.com/wixtoolset/issues/issues/8585
Bob Arnson committed
Sep 2, 2024 at 22:14 UTC
5dc8c8975b2356654410b2ba4755dfa2c32e7b91
6 files changed
+55
-6
src/wix/WixToolset.Core/ExtensibilityServices/FileResolver.cs
+1
-1
@@ -90,7 +90,7 @@ namespace WixToolset.Core.ExtensibilityServices
90
if (-1 != closeParen)
91
{
92
bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length);
93
- path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing brace.
93
+ path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing paren.
94
path = path.TrimStart('\\'); // remove starting '\\' char so the path doesn't look rooted.
95
}
96
}
src/wix/WixToolset.Core/HarvestFilesCommand.cs
+4
-2
@@ -195,14 +195,16 @@ namespace WixToolset.Core
195
if (-1 != closeParen)
196
{
197
bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length);
198
- path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing brace.
198
+ path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing paren.
199
path = path.TrimStart('\\'); // remove starting '\\' char so the path doesn't look rooted.
200
}
201
}
202
203
if (String.IsNullOrEmpty(bindName))
204
{
205
- resultingDirectories.Add(path);
205
+ var unnamedBindPath = this.Context.BindPaths.SingleOrDefault(bp => bp.Name == null)?.Path;
206
+
207
+ resultingDirectories.Add(unnamedBindPath is null ? path : Path.Combine(unnamedBindPath, path));
208
}
209
else
210
{
src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
+29
-3
@@ -238,7 +238,7 @@ namespace WixToolsetTest.CoreIntegration
238
}
239
240
[Fact]
241
- public void CanHarvestFilesWithBindPaths()
241
+ public void CanHarvestFilesWithNamedBindPaths()
242
{
243
var expected = new[]
244
{
@@ -256,6 +256,27 @@ namespace WixToolsetTest.CoreIntegration
256
Build("BindPaths.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected));
257
}
258
259
+ [Fact]
260
+ public void CanHarvestFilesWithUnnamedBindPaths()
261
+ {
262
+ var expected = new[]
263
+ {
264
+ @"flsNNsTNrgmjASmTBbP.45J1F50dEc=PFiles\HarvestedFiles\test1.txt",
265
+ @"flsASLR5pHQzLmWRE.Snra7ndH7sIA=PFiles\HarvestedFiles\test2.txt",
266
+ @"flsTZFPiMHb.qfUxdGKQYrnXOhZ.8M=PFiles\HarvestedFiles\files1_sub1\test10.txt",
267
+ @"flsLGcTTZPIU3ELiWybqnm.PQ0Ih_g=PFiles\HarvestedFiles\files1_sub1\files1_sub2\test120.txt",
268
+ @"fls1Jx2Y9Vea_.WZBH_h2e79arvDRU=PFiles\HarvestedFiles\test3.txt",
269
+ @"flsJ9gNxWaau2X3ufphQuCV9WwAgcw=PFiles\HarvestedFiles\test4.txt",
270
+ @"flswcmX9dpMQytmD_5QA5aJ5szoQVA=PFiles\HarvestedFiles\files2_sub2\test20.txt",
271
+ @"flskKeCKFUtCYMuvw564rgPLJmyBx0=PFiles\HarvestedFiles\files2_sub2\test21.txt",
272
+ @"fls2agLZFnQwjoijShwT9Z0RwHyGrI=PFiles\HarvestedFiles\files2_sub3\FileName.Extension",
273
+ @"fls9UMOE.TOv61JuYF8IhvCKb8eous=PFiles\HarvestedFiles\namedfile.txt",
274
+ @"flsu53T_9CcaBegDflAImGHTajDbJ0=PFiles\HarvestedFiles\unnamedfile.txt",
275
+ };
276
+
277
+ Build("BindPathsUnnamed.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected), addUnnamedBindPath: true);
278
+ }
279
+
280
[Fact]
281
public void CanHarvestFilesInStandardDirectory()
282
{
@@ -325,7 +346,7 @@ namespace WixToolsetTest.CoreIntegration
346
Assert.Equal(sortedExpected, actual);
347
}
348
328
- private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool warningsAsErrors = true, params string[] additionalCommandLineArguments)
349
+ private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool warningsAsErrors = true, bool addUnnamedBindPath = false, params string[] additionalCommandLineArguments)
350
{
351
var folder = TestData.Get("TestData", "HarvestFiles");
352
@@ -341,12 +362,17 @@ namespace WixToolsetTest.CoreIntegration
362
"build",
363
Path.Combine(folder, file),
364
"-intermediateFolder", intermediateFolder,
344
- "-bindpath", folder,
365
"-bindpath", @$"ToBeHarvested={folder}\files1",
366
"-bindpath", @$"ToBeHarvested={folder}\files2",
367
"-o", msiPath,
368
};
369
370
+ if (addUnnamedBindPath)
371
+ {
372
+ arguments.Add("-bindpath");
373
+ arguments.Add(Path.Combine(folder, "unnamedbindpath"));
374
+ }
375
+
376
if (additionalCommandLineArguments.Length > 0)
377
{
378
arguments.AddRange(additionalCommandLineArguments);
src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/BindPathsUnnamed.wxs
new
+19
@@ -0,0 +1,19 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Name="HarvestedFiles" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3
+ <MajorUpgrade DowngradeErrorMessage="Downgrade error message." />
4
+
5
+ <Feature Id="ProductFeature">
6
+ <ComponentGroupRef Id="Files" />
7
+ </Feature>
8
+
9
+ <ComponentGroup Id="Files" Directory="ProgramFilesFolder" Subdirectory="HarvestedFiles">
10
+ <Files Include="!(bindpath.ToBeHarvested)\**">
11
+ <Exclude Files="!(bindpath.ToBeHarvested)\notatest.txt" />
12
+ <Exclude Files="!(bindpath.ToBeHarvested)\**\pleasedontincludeme.dat" />
13
+ </Files>
14
+
15
+ <!-- Include everything from the unnamed bindpath too. -->
16
+ <Files Include="**" />
17
+ </ComponentGroup>
18
+ </Package>
19
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/namedfile.txt
new
+1
@@ -0,0 +1 @@
1
+This is test.txt.
src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/unnamedfile.txt
new
+1
@@ -0,0 +1 @@
1
+This is test.txt.