From c3bd9119779253dd0811e685debd42fcdf3b99c8 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sun, 16 Nov 2025 16:38:24 -0500 Subject: Harvest relative paths relative to source file. Ignores unnamed bind paths (sadly). Fixes https://github.com/wixtoolset/issues/issues/9097 --- .../HarvestFilesAndPayloadsCommand.cs | 4 +-- .../HarvestFilesFixture.cs | 42 +++++++++++----------- .../TestData/HarvestFiles/BindPathsUnnamed.wxs | 19 ---------- .../TestData/HarvestFiles/RelativeToSource.wxs | 6 ++++ .../HarvestFiles/unnamedbindpath/namedfile.txt | 1 - .../HarvestFiles/unnamedbindpath/unnamedfile.txt | 1 - 6 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/BindPathsUnnamed.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/RelativeToSource.wxs delete mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/namedfile.txt delete mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/unnamedfile.txt diff --git a/src/wix/WixToolset.Core/HarvestFilesAndPayloadsCommand.cs b/src/wix/WixToolset.Core/HarvestFilesAndPayloadsCommand.cs index 3b1b1358..b8265bc1 100644 --- a/src/wix/WixToolset.Core/HarvestFilesAndPayloadsCommand.cs +++ b/src/wix/WixToolset.Core/HarvestFilesAndPayloadsCommand.cs @@ -275,9 +275,7 @@ namespace WixToolset.Core if (String.IsNullOrEmpty(bindName)) { - var unnamedBindPath = this.Context.BindPaths.FirstOrDefault(bp => bp.Name == null)?.Path; - - resultingDirectories.Add(unnamedBindPath is null ? path : Path.Combine(unnamedBindPath, path)); + resultingDirectories.Add(path); } else { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs index 97f3e442..4d7253b8 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs @@ -24,7 +24,7 @@ namespace WixToolsetTest.CoreIntegration { 10, }, messages); - }); + }, assertSuccess: false); } [Fact] @@ -37,7 +37,7 @@ namespace WixToolsetTest.CoreIntegration { "8600: Inclusions and exclusions resulted in zero files harvested. Unless that is expected, you should verify paths, inclusions, and exclusions on Files or Payloads for accuracy.", }, messages); - }); + }, assertSuccess: false); } [Fact] @@ -53,7 +53,7 @@ namespace WixToolsetTest.CoreIntegration @"8601: Missing directory for harvesting files: Could not find a part of the path '\files2\ThisDirectoryIsAlsoMissing'.", @"8600: Inclusions and exclusions resulted in zero files harvested. Unless that is expected, you should verify paths, inclusions, and exclusions on Files or Payloads for accuracy.", }, messages); - }); + }, assertSuccess: false); } [Fact] @@ -93,7 +93,7 @@ namespace WixToolsetTest.CoreIntegration 8602, 8602, }, messages); - }); + }, assertSuccess: false); } [Fact] @@ -109,7 +109,7 @@ namespace WixToolsetTest.CoreIntegration 267, 267, }, messages); - }); + }, assertSuccess: false); } [Fact] @@ -300,24 +300,19 @@ namespace WixToolsetTest.CoreIntegration } [Fact] - public void CanHarvestFilesWithUnnamedBindPaths() + public void CanHarvestFilesRelativeToSourceFile() { var expected = new[] { - @"flsNNsTNrgmjASmTBbP.45J1F50dEc=PFiles\HarvestedFiles\test1.txt", - @"flsASLR5pHQzLmWRE.Snra7ndH7sIA=PFiles\HarvestedFiles\test2.txt", - @"flsTZFPiMHb.qfUxdGKQYrnXOhZ.8M=PFiles\HarvestedFiles\files1_sub1\test10.txt", - @"flsLGcTTZPIU3ELiWybqnm.PQ0Ih_g=PFiles\HarvestedFiles\files1_sub1\files1_sub2\test120.txt", - @"fls1Jx2Y9Vea_.WZBH_h2e79arvDRU=PFiles\HarvestedFiles\test3.txt", - @"flsJ9gNxWaau2X3ufphQuCV9WwAgcw=PFiles\HarvestedFiles\test4.txt", - @"flswcmX9dpMQytmD_5QA5aJ5szoQVA=PFiles\HarvestedFiles\files2_sub2\test20.txt", - @"flskKeCKFUtCYMuvw564rgPLJmyBx0=PFiles\HarvestedFiles\files2_sub2\test21.txt", - @"fls2agLZFnQwjoijShwT9Z0RwHyGrI=PFiles\HarvestedFiles\files2_sub3\FileName.Extension", - @"fls9UMOE.TOv61JuYF8IhvCKb8eous=PFiles\HarvestedFiles\namedfile.txt", - @"flsu53T_9CcaBegDflAImGHTajDbJ0=PFiles\HarvestedFiles\unnamedfile.txt", + @"flsiYjLzK34LeZEChPfagEeCq391QE=PFiles\Example Corporation HarvestedFiles\BadAuthoring.wxs", + @"flssFAX35joEC73c.9dGg2Cxy9yZHg=PFiles\Example Corporation HarvestedFiles\BadDirectory.wxs", + @"flsYgiwrDUkZnBEK6iUMkxxaJlD8yQ=PFiles\Example Corporation HarvestedFiles\test1.txt", + @"flsj.cb0sFWqIPHPFSKJSEEaPDuAQ4=PFiles\Example Corporation HarvestedFiles\test2.txt", + @"flsD7JQZm.Ts2375WMT.zsTxqCAf.s=PFiles\Example Corporation HarvestedFiles\files1_sub1\test10.txt", + @"flslrDWblm4pE.4i4jR58_XyYMmR8I=PFiles\Example Corporation HarvestedFiles\files1_sub1\files1_sub2\test120.txt", }; - Build("BindPathsUnnamed.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected), addUnnamedBindPaths: true); + Build("RelativeToSource.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected), addUnnamedBindPaths: true); } [Fact] @@ -423,12 +418,12 @@ namespace WixToolsetTest.CoreIntegration WixAssert.CompareLineByLine(sortedExpected, actual); } - private static void Build(string file, Action tester, bool isMsi = true, bool warningsAsErrors = true, bool addUnnamedBindPaths = false, params string[] additionalCommandLineArguments) + private static void Build(string file, Action tester, bool isMsi = true, bool warningsAsErrors = true, bool addUnnamedBindPaths = false, bool assertSuccess = true, params string[] additionalCommandLineArguments) { - Build(file, (msiPath, sourceFolder, baseFolder, result) => tester(msiPath, result), isMsi, warningsAsErrors, addUnnamedBindPaths, additionalCommandLineArguments); + Build(file, (msiPath, sourceFolder, baseFolder, result) => tester(msiPath, result), isMsi, warningsAsErrors, addUnnamedBindPaths, assertSuccess, additionalCommandLineArguments); } - private static void Build(string file, Action tester, bool isMsi = true, bool warningsAsErrors = true, bool addUnnamedBindPaths = false, params string[] additionalCommandLineArguments) + private static void Build(string file, Action tester, bool isMsi = true, bool warningsAsErrors = true, bool addUnnamedBindPaths = false, bool assertSuccess = true, params string[] additionalCommandLineArguments) { var sourceFolder = TestData.Get("TestData", "HarvestFiles"); @@ -465,6 +460,11 @@ namespace WixToolsetTest.CoreIntegration var result = WixRunner.Execute(warningsAsErrors, arguments.ToArray()); + if (assertSuccess) + { + result.AssertSuccess(); + } + tester(msiPath, sourceFolder, baseFolder, result); } } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/BindPathsUnnamed.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/BindPathsUnnamed.wxs deleted file mode 100644 index cd764926..00000000 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/BindPathsUnnamed.wxs +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/RelativeToSource.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/RelativeToSource.wxs new file mode 100644 index 00000000..80dfaa6f --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/RelativeToSource.wxs @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/namedfile.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/namedfile.txt deleted file mode 100644 index d32727e0..00000000 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/namedfile.txt +++ /dev/null @@ -1 +0,0 @@ -This is test.txt. diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/unnamedfile.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/unnamedfile.txt deleted file mode 100644 index d32727e0..00000000 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/unnamedbindpath/unnamedfile.txt +++ /dev/null @@ -1 +0,0 @@ -This is test.txt. -- cgit v1.2.3-55-g6feb