@joebigelow / wix-1 / commits / 9023fd4d

Handle error case when payload is missing both Name and SourceFile

Fixes 7333 and 7347

Rob Mensching committed Apr 3, 2023 at 16:32 UTC 9023fd4d6dd4339003defcfb12002432357193b9
4 files changed +90
src/wix/WixToolset.Core/Compile/CompilerPayload.cs
+5
@@ -207,6 +207,11 @@ namespace WixToolset.Core
207 this.DownloadUrl = null;
208 }
209
210 + if (String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.SourceFile))
211 + {
212 + this.Core.Write(ErrorMessages.ExpectedAttributes(this.SourceLineNumbers, this.Element.Name.LocalName, "Name", "SourceFile"));
213 + }
214 +
215 if (!this.Core.EncounteredError)
216 {
217 symbol = this.Core.AddSymbol(new WixBundlePayloadSymbol(this.SourceLineNumbers, this.Id)
src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
+54
@@ -405,6 +405,60 @@ namespace WixToolsetTest.CoreIntegration
405 }
406 }
407
408 + [Fact]
409 + public void CannotBuildBundleMissingMsiSource()
410 + {
411 + var folder = TestData.Get(@"TestData");
412 +
413 + using (var fs = new DisposableFileSystem())
414 + {
415 + var baseFolder = fs.GetFolder();
416 + var intermediateFolder = Path.Combine(baseFolder, "obj");
417 +
418 + var result = WixRunner.Execute(new[]
419 + {
420 + "build",
421 + Path.Combine(folder, "BundleWithMissingSource", "BundleMissingMsiSource.wxs"),
422 + "-bindpath", Path.Combine(folder, ".Data"),
423 + "-intermediateFolder", intermediateFolder,
424 + "-o", Path.Combine(baseFolder, @"bin\test.exe")
425 + });
426 +
427 + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "<testdata>")).ToArray();
428 + WixAssert.CompareLineByLine(new[]
429 + {
430 + @"The MsiPackage element's Name or SourceFile attribute was not found; one of these is required."
431 + }, message);
432 + }
433 + }
434 +
435 + [Fact]
436 + public void CannotBuildBundleMissingMsuSource()
437 + {
438 + var folder = TestData.Get(@"TestData");
439 +
440 + using (var fs = new DisposableFileSystem())
441 + {
442 + var baseFolder = fs.GetFolder();
443 + var intermediateFolder = Path.Combine(baseFolder, "obj");
444 +
445 + var result = WixRunner.Execute(new[]
446 + {
447 + "build",
448 + Path.Combine(folder, "BundleWithMissingSource", "BundleMissingMsuSource.wxs"),
449 + "-bindpath", Path.Combine(folder, ".Data"),
450 + "-intermediateFolder", intermediateFolder,
451 + "-o", Path.Combine(baseFolder, @"bin\test.exe")
452 + });
453 +
454 + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "<testdata>")).ToArray();
455 + WixAssert.CompareLineByLine(new[]
456 + {
457 + @"The MsuPackage element's Name or SourceFile attribute was not found; one of these is required."
458 + }, message);
459 + }
460 + }
461 +
462 [Fact]
463 public void CannotBuildBundleWithInvalidIcon()
464 {
src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsiSource.wxs new
+15
@@ -0,0 +1,15 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Bundle Name="BundleMissingMsiSource"
3 + Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="B94478B1-E1F3-4700-9CE8-6AA090854AEC">
4 + <BootstrapperApplication>
5 + <BootstrapperApplicationDll SourceFile="fakeba.dll" />
6 + </BootstrapperApplication>
7 +
8 + <Chain>
9 + <MsiPackage
10 + Id="MsiPackage1"
11 + DisplayName="Msi Package #1"
12 + DownloadUrl="http://example.com/test.msi" />
13 + </Chain>
14 + </Bundle>
15 +</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsuSource.wxs new
+16
@@ -0,0 +1,16 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Bundle Name="BundleMissingMsuSource"
3 + Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="B94478B1-E1F3-4700-9CE8-6AA090854AEC">
4 + <BootstrapperApplication>
5 + <BootstrapperApplicationDll SourceFile="fakeba.dll" />
6 + </BootstrapperApplication>
7 +
8 + <Chain>
9 + <MsuPackage
10 + Id="MsuPackage1"
11 + DetectCondition="TODO"
12 + DisplayName="MSU Package #1"
13 + DownloadUrl="http://example.com/test.msu" />
14 + </Chain>
15 + </Bundle>
16 +</Wix>