From e74bc9e2bcca9ba4378e8a9c87f5081295616902 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 12 Jan 2023 16:15:31 -0800 Subject: Add support for ALLUSERS=2 with Scope=perUserOrMachine Fixes 7137 --- src/wix/WixToolset.Core/Compiler_Package.cs | 12 +++- .../AllUsersFixture.cs | 77 ++++++++++++++++++++++ .../TestData/AllUsers/PerMachine.wxs | 15 +++++ .../TestData/AllUsers/PerUser.wxs | 15 +++++ .../TestData/AllUsers/PerUserOrMachine.wxs | 15 +++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/AllUsersFixture.cs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs (limited to 'src') diff --git a/src/wix/WixToolset.Core/Compiler_Package.cs b/src/wix/WixToolset.Core/Compiler_Package.cs index e59c394a..e0b8a3f6 100644 --- a/src/wix/WixToolset.Core/Compiler_Package.cs +++ b/src/wix/WixToolset.Core/Compiler_Package.cs @@ -31,6 +31,7 @@ namespace WixToolset.Core var productCode = "*"; string productLanguage = null; var isPerMachine = true; + var isPerUserOrMachine = false; string upgradeCode = null; string manufacturer = null; string version = null; @@ -91,6 +92,10 @@ namespace WixToolset.Core isPerMachine = false; sourceBits |= 8; break; + case "perUserOrMachine": + isPerMachine = false; + isPerUserOrMachine = true; + break; default: this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, installScope, "perMachine", "perUser")); break; @@ -169,7 +174,12 @@ namespace WixToolset.Core this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "UpgradeCode"), upgradeCode, false, false, false, true); } - if (isPerMachine) + if (isPerUserOrMachine) + { + this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ALLUSERS"), "2", false, false, false, false); + this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "MSIINSTALLPERUSER"), "1", false, false, false, false); + } + else if (isPerMachine) { this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ALLUSERS"), "1", false, false, false, false); } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/AllUsersFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/AllUsersFixture.cs new file mode 100644 index 00000000..0c1fd9e0 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/AllUsersFixture.cs @@ -0,0 +1,77 @@ +// 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. + +namespace WixToolsetTest.CoreIntegration +{ + using System.IO; + using System.Linq; + using WixInternal.Core.TestPackage; + using WixInternal.TestSupport; + using Xunit; + + public class AllUsersFixture + { + [Fact] + public void CanCheckPerMachineMsi() + { + var propertyRows = BuildAndQueryPropertyTable("PerMachine.wxs"); + + WixAssert.CompareLineByLine(new[] + { + "_SummaryInformation:WordCount\t2", + "Property:ALLUSERS\t1" + }, propertyRows); + } + + [Fact] + public void CanCheckPerUserMsi() + { + var propertyRows = BuildAndQueryPropertyTable("PerUser.wxs"); + + WixAssert.CompareLineByLine(new[] + { + "_SummaryInformation:WordCount\t10" + }, propertyRows); + } + + [Fact] + public void CanCheckPerUserOrMachineMsi() + { + var propertyRows = BuildAndQueryPropertyTable("PerUserOrMachine.wxs"); + + WixAssert.CompareLineByLine(new[] + { + "_SummaryInformation:WordCount\t2", + "Property:ALLUSERS\t2", + "Property:MSIINSTALLPERUSER\t1" + }, propertyRows); + } + + private static string[] BuildAndQueryPropertyTable(string file) + { + var folder = TestData.Get("TestData", "AllUsers"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var binFolder = Path.Combine(baseFolder, "bin"); + var msiPath = Path.Combine(binFolder, "test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, file), + "-intermediateFolder", intermediateFolder, + "-bindpath", folder, + "-o", msiPath, + }); + result.AssertSuccess(); + + return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" }) + .Where(s => s.StartsWith("Property:ALLUSERS") || s.StartsWith("Property:MSIINSTALLPERUSER") || s.StartsWith("_SummaryInformation:WordCount")) + .OrderBy(s => s) + .ToArray(); + } + } + } +} diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs new file mode 100644 index 00000000..3f19277b --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs new file mode 100644 index 00000000..12ba9c59 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs new file mode 100644 index 00000000..293cf1fa --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + -- cgit v1.2.3-55-g6feb