@joebigelow / wix / commits / c1605aa5

Require or recommend ExePackage/@DetectCondition

Fixes wixtoolset/issues#6197

Rob Mensching committed Jan 8, 2021 at 13:46 UTC c1605aa577e304fe0fb4c57056b58754bfaf3666
5 files changed +88 -2
src/WixToolset.Core/Compiler_Bundle.cs
+15 -1
@@ -2232,7 +2232,7 @@ namespace WixToolset.Core
2232 allowed = (packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msp);
2233 break;
2234 case "DetectCondition":
2235 - detectCondition = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
2235 + detectCondition = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty);
2236 allowed = (packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msu);
2237 break;
2238 case "Protocol":
@@ -2394,6 +2394,20 @@ namespace WixToolset.Core
2394 perMachine = YesNoDefaultType.Default;
2395 }
2396
2397 + // Detect condition is recommended or required for Exe and Msu packages
2398 + // (depending on whether uninstall arguments were provided).
2399 + if ((packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msu) && String.IsNullOrEmpty(detectCondition))
2400 + {
2401 + if (String.IsNullOrEmpty(uninstallCommand))
2402 + {
2403 + this.Core.Write(WarningMessages.DetectConditionRecommended(sourceLineNumbers, node.Name.LocalName));
2404 + }
2405 + else
2406 + {
2407 + this.Core.Write(ErrorMessages.ExpectedAttributeWithValueWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "DetectCondition", "UninstallCommand"));
2408 + }
2409 + }
2410 +
2411 // Now that the package ID is known, we can parse the extension attributes...
2412 var contextValues = new Dictionary<string, string>() { { "PackageId", id.Id } };
2413 foreach (var attribute in extensionAttributes)
src/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs new
+52
@@ -0,0 +1,52 @@
1 +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2 +
3 +namespace WixToolsetTest.CoreIntegration
4 +{
5 + using System.IO;
6 + using WixBuildTools.TestSupport;
7 + using WixToolset.Core.TestPackage;
8 + using Xunit;
9 +
10 + public class ExePackageFixture
11 + {
12 + [Fact]
13 + public void ErrorWhenMissingDetectCondition()
14 + {
15 + var folder = TestData.Get(@"TestData", "ExePackage");
16 +
17 + using (var fs = new DisposableFileSystem())
18 + {
19 + var baseFolder = fs.GetFolder();
20 +
21 + var result = WixRunner.Execute(new[]
22 + {
23 + "build",
24 + Path.Combine(folder, "MissingDetectCondition.wxs"),
25 + "-o", Path.Combine(baseFolder, "test.wixlib")
26 + });
27 +
28 + Assert.Equal(1153, result.ExitCode);
29 + }
30 + }
31 +
32 + [Fact]
33 + public void ErrorWhenRequireDetectCondition()
34 + {
35 + var folder = TestData.Get(@"TestData", "ExePackage");
36 +
37 + using (var fs = new DisposableFileSystem())
38 + {
39 + var baseFolder = fs.GetFolder();
40 +
41 + var result = WixRunner.Execute(new[]
42 + {
43 + "build",
44 + Path.Combine(folder, "RequireDetectCondition.wxs"),
45 + "-o", Path.Combine(baseFolder, "test.wixlib")
46 + });
47 +
48 + Assert.Equal(401, result.ExitCode);
49 + }
50 + }
51 + }
52 +}
src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/MissingDetectCondition.wxs new
+9
@@ -0,0 +1,9 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <PackageGroup Id="TestPackageGroup">
5 + <ExePackage InstallCommand="-install"
6 + SourceFile="testsetup.exe" />
7 + </PackageGroup>
8 + </Fragment>
9 +</Wix>
src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/RequireDetectCondition.wxs new
+11
@@ -0,0 +1,11 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <PackageGroup Id="TestPackageGroup">
5 + <ExePackage DetectCondition=""
6 + InstallCommand="-install"
7 + UninstallCommand="-uninstall"
8 + SourceFile="testsetup.exe" />
9 + </PackageGroup>
10 + </Fragment>
11 +</Wix>
src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExePackageGroup.wxs
+1 -1
@@ -2,7 +2,7 @@
2 <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <PackageGroup Id="BundlePackages">
5 - <ExePackage SourceFile="burn.exe" />
5 + <ExePackage DetectCondition="DetectedSomething" SourceFile="burn.exe" />
6 </PackageGroup>
7 </Fragment>
8 </Wix>