From 9023fd4d6dd4339003defcfb12002432357193b9 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 3 Apr 2023 16:32:29 -0700 Subject: Handle error case when payload is missing both Name and SourceFile Fixes 7333 and 7347 --- src/wix/WixToolset.Core/Compile/CompilerPayload.cs | 5 ++ .../BundleFixture.cs | 54 ++++++++++++++++++++++ .../BundleMissingMsiSource.wxs | 15 ++++++ .../BundleMissingMsuSource.wxs | 16 +++++++ 4 files changed, 90 insertions(+) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsiSource.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsuSource.wxs diff --git a/src/wix/WixToolset.Core/Compile/CompilerPayload.cs b/src/wix/WixToolset.Core/Compile/CompilerPayload.cs index e3dfc342..40205f19 100644 --- a/src/wix/WixToolset.Core/Compile/CompilerPayload.cs +++ b/src/wix/WixToolset.Core/Compile/CompilerPayload.cs @@ -207,6 +207,11 @@ namespace WixToolset.Core this.DownloadUrl = null; } + if (String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.SourceFile)) + { + this.Core.Write(ErrorMessages.ExpectedAttributes(this.SourceLineNumbers, this.Element.Name.LocalName, "Name", "SourceFile")); + } + if (!this.Core.EncounteredError) { symbol = this.Core.AddSymbol(new WixBundlePayloadSymbol(this.SourceLineNumbers, this.Id) diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index 2cc7a681..5c51ecdb 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -405,6 +405,60 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CannotBuildBundleMissingMsiSource() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithMissingSource", "BundleMissingMsiSource.wxs"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(baseFolder, @"bin\test.exe") + }); + + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "")).ToArray(); + WixAssert.CompareLineByLine(new[] + { + @"The MsiPackage element's Name or SourceFile attribute was not found; one of these is required." + }, message); + } + } + + [Fact] + public void CannotBuildBundleMissingMsuSource() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithMissingSource", "BundleMissingMsuSource.wxs"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(baseFolder, @"bin\test.exe") + }); + + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "")).ToArray(); + WixAssert.CompareLineByLine(new[] + { + @"The MsuPackage element's Name or SourceFile attribute was not found; one of these is required." + }, message); + } + } + [Fact] public void CannotBuildBundleWithInvalidIcon() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsiSource.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsiSource.wxs new file mode 100644 index 00000000..b2141a70 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsiSource.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsuSource.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsuSource.wxs new file mode 100644 index 00000000..1e2d0e6c --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithMissingSource/BundleMissingMsuSource.wxs @@ -0,0 +1,16 @@ + + + + + + + + + + + -- cgit v1.2.3-55-g6feb