Add support for ALLUSERS=2 with Scope=perUserOrMachine
Fixes 7137
Rob Mensching committed
Jan 12, 2023 at 16:15 UTC
e74bc9e2bcca9ba4378e8a9c87f5081295616902
5 files changed
+133
-1
src/wix/WixToolset.Core/Compiler_Package.cs
+11
-1
@@ -31,6 +31,7 @@ namespace WixToolset.Core
31
var productCode = "*";
32
string productLanguage = null;
33
var isPerMachine = true;
34
+ var isPerUserOrMachine = false;
35
string upgradeCode = null;
36
string manufacturer = null;
37
string version = null;
@@ -91,6 +92,10 @@ namespace WixToolset.Core
92
isPerMachine = false;
93
sourceBits |= 8;
94
break;
95
+ case "perUserOrMachine":
96
+ isPerMachine = false;
97
+ isPerUserOrMachine = true;
98
+ break;
99
default:
100
this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, installScope, "perMachine", "perUser"));
101
break;
@@ -169,7 +174,12 @@ namespace WixToolset.Core
174
this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "UpgradeCode"), upgradeCode, false, false, false, true);
175
}
176
172
- if (isPerMachine)
177
+ if (isPerUserOrMachine)
178
+ {
179
+ this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ALLUSERS"), "2", false, false, false, false);
180
+ this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "MSIINSTALLPERUSER"), "1", false, false, false, false);
181
+ }
182
+ else if (isPerMachine)
183
{
184
this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ALLUSERS"), "1", false, false, false, false);
185
}
src/wix/test/WixToolsetTest.CoreIntegration/AllUsersFixture.cs
new
+77
@@ -0,0 +1,77 @@
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 System.Linq;
7
+ using WixInternal.Core.TestPackage;
8
+ using WixInternal.TestSupport;
9
+ using Xunit;
10
+
11
+ public class AllUsersFixture
12
+ {
13
+ [Fact]
14
+ public void CanCheckPerMachineMsi()
15
+ {
16
+ var propertyRows = BuildAndQueryPropertyTable("PerMachine.wxs");
17
+
18
+ WixAssert.CompareLineByLine(new[]
19
+ {
20
+ "_SummaryInformation:WordCount\t2",
21
+ "Property:ALLUSERS\t1"
22
+ }, propertyRows);
23
+ }
24
+
25
+ [Fact]
26
+ public void CanCheckPerUserMsi()
27
+ {
28
+ var propertyRows = BuildAndQueryPropertyTable("PerUser.wxs");
29
+
30
+ WixAssert.CompareLineByLine(new[]
31
+ {
32
+ "_SummaryInformation:WordCount\t10"
33
+ }, propertyRows);
34
+ }
35
+
36
+ [Fact]
37
+ public void CanCheckPerUserOrMachineMsi()
38
+ {
39
+ var propertyRows = BuildAndQueryPropertyTable("PerUserOrMachine.wxs");
40
+
41
+ WixAssert.CompareLineByLine(new[]
42
+ {
43
+ "_SummaryInformation:WordCount\t2",
44
+ "Property:ALLUSERS\t2",
45
+ "Property:MSIINSTALLPERUSER\t1"
46
+ }, propertyRows);
47
+ }
48
+
49
+ private static string[] BuildAndQueryPropertyTable(string file)
50
+ {
51
+ var folder = TestData.Get("TestData", "AllUsers");
52
+
53
+ using (var fs = new DisposableFileSystem())
54
+ {
55
+ var baseFolder = fs.GetFolder();
56
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
57
+ var binFolder = Path.Combine(baseFolder, "bin");
58
+ var msiPath = Path.Combine(binFolder, "test.msi");
59
+
60
+ var result = WixRunner.Execute(new[]
61
+ {
62
+ "build",
63
+ Path.Combine(folder, file),
64
+ "-intermediateFolder", intermediateFolder,
65
+ "-bindpath", folder,
66
+ "-o", msiPath,
67
+ });
68
+ result.AssertSuccess();
69
+
70
+ return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" })
71
+ .Where(s => s.StartsWith("Property:ALLUSERS") || s.StartsWith("Property:MSIINSTALLPERUSER") || s.StartsWith("_SummaryInformation:WordCount"))
72
+ .OrderBy(s => s)
73
+ .ToArray();
74
+ }
75
+ }
76
+ }
77
+}
src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs
new
+15
@@ -0,0 +1,15 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Version="1"
3
+ Name="MsiPackage"
4
+ Manufacturer="Example Corporation"
5
+ UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
6
+ Scope="perMachine">
7
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
8
+
9
+ <Feature Id="ProductFeature" Title="Feature title">
10
+ <Component Directory="DesktopFolder">
11
+ <File Source="PerUser.wxs" />
12
+ </Component>
13
+ </Feature>
14
+ </Package>
15
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs
new
+15
@@ -0,0 +1,15 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Version="1"
3
+ Name="MsiPackage"
4
+ Manufacturer="Example Corporation"
5
+ UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
6
+ Scope="perUser">
7
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
8
+
9
+ <Feature Id="ProductFeature" Title="Feature title">
10
+ <Component Directory="DesktopFolder">
11
+ <File Source="PerUser.wxs" />
12
+ </Component>
13
+ </Feature>
14
+ </Package>
15
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs
new
+15
@@ -0,0 +1,15 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Version="1"
3
+ Name="MsiPackage"
4
+ Manufacturer="Example Corporation"
5
+ UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
6
+ Scope="perUserOrMachine">
7
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
8
+
9
+ <Feature Id="ProductFeature" Title="Feature title">
10
+ <Component Directory="DesktopFolder">
11
+ <File Source="PerUser.wxs" />
12
+ </Component>
13
+ </Feature>
14
+ </Package>
15
+</Wix>