diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-01-08 13:46:36 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-01-08 15:47:31 -0800 |
| commit | c1605aa577e304fe0fb4c57056b58754bfaf3666 (patch) | |
| tree | 2bd363058d48134ef23ddcf557d91386295baecc /src | |
| parent | e35ee2e8c58bf55da5f3d04915d588fb04d6809d (diff) | |
| download | wix-c1605aa577e304fe0fb4c57056b58754bfaf3666.tar.gz wix-c1605aa577e304fe0fb4c57056b58754bfaf3666.tar.bz2 wix-c1605aa577e304fe0fb4c57056b58754bfaf3666.zip | |
Require or recommend ExePackage/@DetectCondition
Fixes wixtoolset/issues#6197
Diffstat (limited to 'src')
5 files changed, 88 insertions, 2 deletions
diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index 40b44bbd..1bee3823 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs | |||
| @@ -2232,7 +2232,7 @@ namespace WixToolset.Core | |||
| 2232 | allowed = (packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msp); | 2232 | allowed = (packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msp); |
| 2233 | break; | 2233 | break; |
| 2234 | case "DetectCondition": | 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); | 2236 | allowed = (packageType == WixBundlePackageType.Exe || packageType == WixBundlePackageType.Msu); |
| 2237 | break; | 2237 | break; |
| 2238 | case "Protocol": | 2238 | case "Protocol": |
| @@ -2394,6 +2394,20 @@ namespace WixToolset.Core | |||
| 2394 | perMachine = YesNoDefaultType.Default; | 2394 | perMachine = YesNoDefaultType.Default; |
| 2395 | } | 2395 | } |
| 2396 | 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 | |||
| 2397 | // Now that the package ID is known, we can parse the extension attributes... | 2411 | // Now that the package ID is known, we can parse the extension attributes... |
| 2398 | var contextValues = new Dictionary<string, string>() { { "PackageId", id.Id } }; | 2412 | var contextValues = new Dictionary<string, string>() { { "PackageId", id.Id } }; |
| 2399 | foreach (var attribute in extensionAttributes) | 2413 | foreach (var attribute in extensionAttributes) |
diff --git a/src/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs b/src/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs new file mode 100644 index 00000000..e2306dcd --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs | |||
| @@ -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 | } | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/MissingDetectCondition.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/MissingDetectCondition.wxs new file mode 100644 index 00000000..21b4269b --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/MissingDetectCondition.wxs | |||
| @@ -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> | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/RequireDetectCondition.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/RequireDetectCondition.wxs new file mode 100644 index 00000000..42253f18 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/RequireDetectCondition.wxs | |||
| @@ -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> | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExePackageGroup.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExePackageGroup.wxs index 9d7a9511..cad1f049 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExePackageGroup.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExePackageGroup.wxs | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | 2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> |
| 3 | <Fragment> | 3 | <Fragment> |
| 4 | <PackageGroup Id="BundlePackages"> | 4 | <PackageGroup Id="BundlePackages"> |
| 5 | <ExePackage SourceFile="burn.exe" /> | 5 | <ExePackage DetectCondition="DetectedSomething" SourceFile="burn.exe" /> |
| 6 | </PackageGroup> | 6 | </PackageGroup> |
| 7 | </Fragment> | 7 | </Fragment> |
| 8 | </Wix> | 8 | </Wix> |
