Allow custom package comments
Fixes #7369
Marco Stadler committed
Apr 24, 2023 at 11:49 UTC
e0641f1479c6f67f6ec119d448b66a74ad5d6b88
12 files changed
+295
-13
src/wix/WixToolset.Core/Compiler_Module.cs
+9
-5
@@ -25,6 +25,7 @@ namespace WixToolset.Core
25
string moduleId = null;
26
string version = null;
27
var setCodepage = false;
28
+ var setComments = false;
29
var setPackageName = false;
30
var setKeywords = false;
31
var ignoredForMergeModules = false;
@@ -206,7 +207,7 @@ namespace WixToolset.Core
207
this.ParseSubstitutionElement(child);
208
break;
209
case "SummaryInformation":
209
- this.ParseSummaryInformationElement(child, ref setCodepage, ref setPackageName, ref setKeywords, ref ignoredForMergeModules);
210
+ this.ParseSummaryInformationElement(child, ref setCodepage, ref setComments, ref setPackageName, ref setKeywords, ref ignoredForMergeModules);
211
break;
212
case "UI":
213
this.ParseUIElement(child);
@@ -274,11 +275,14 @@ namespace WixToolset.Core
275
Value = "0"
276
});
277
277
- this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
278
+ if (!setComments)
279
{
279
- PropertyId = SummaryInformationType.Comments,
280
- Value = String.Format(CultureInfo.InvariantCulture, "This merge module contains the logic and data required to install {0}.", this.activeName)
281
- });
280
+ this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
281
+ {
282
+ PropertyId = SummaryInformationType.Comments,
283
+ Value = String.Format(CultureInfo.InvariantCulture, "This merge module contains the logic and data required to install {0}.", this.activeName)
284
+ });
285
+ }
286
287
this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, this.activeLanguage);
288
}
src/wix/WixToolset.Core/Compiler_Package.cs
+27
-8
@@ -37,6 +37,7 @@ namespace WixToolset.Core
37
string version = null;
38
string symbols = null;
39
var isCodepageSet = false;
40
+ var isCommentsSet = false;
41
var isPackageNameSet = false;
42
var isKeywordsSet = false;
43
var isPackageAuthorSet = false;
@@ -190,12 +191,6 @@ namespace WixToolset.Core
191
Value = "Installation Database"
192
});
193
193
- this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
194
- {
195
- PropertyId = SummaryInformationType.Comments,
196
- Value = String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
197
- });
198
-
194
this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, productLanguage);
195
196
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
@@ -334,7 +329,7 @@ namespace WixToolset.Core
329
this.ParseStandardDirectoryElement(child);
330
break;
331
case "SummaryInformation":
337
- this.ParseSummaryInformationElement(child, ref isCodepageSet, ref isPackageNameSet, ref isKeywordsSet, ref isPackageAuthorSet);
332
+ this.ParseSummaryInformationElement(child, ref isCodepageSet, ref isCommentsSet, ref isPackageNameSet, ref isKeywordsSet, ref isPackageAuthorSet);
333
break;
334
case "SymbolPath":
335
if (null != symbols)
@@ -383,6 +378,15 @@ namespace WixToolset.Core
378
Codepage = codepage,
379
});
380
381
+ if (!isCommentsSet)
382
+ {
383
+ this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
384
+ {
385
+ PropertyId = SummaryInformationType.Comments,
386
+ Value = String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
387
+ });
388
+ }
389
+
390
if (!isPackageNameSet)
391
{
392
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
@@ -780,13 +784,15 @@ namespace WixToolset.Core
784
/// </summary>
785
/// <param name="node">Element to parse.</param>
786
/// <param name="isCodepageSet"></param>
787
+ /// <param name="isCommentsSet"></param>
788
/// <param name="isPackageNameSet"></param>
789
/// <param name="isKeywordsSet"></param>
790
/// <param name="isPackageAuthorSet"></param>
786
- private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSet, ref bool isPackageNameSet, ref bool isKeywordsSet, ref bool isPackageAuthorSet)
791
+ private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSet, ref bool isCommentsSet, ref bool isPackageNameSet, ref bool isKeywordsSet, ref bool isPackageAuthorSet)
792
{
793
var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
794
string codepage = null;
795
+ string comments = null;
796
string packageName = null;
797
string keywords = null;
798
string packageAuthor = null;
@@ -800,6 +806,9 @@ namespace WixToolset.Core
806
case "Codepage":
807
codepage = this.Core.GetAttributeLocalizableCodePageValue(sourceLineNumbers, attrib, true);
808
break;
809
+ case "Comments":
810
+ comments = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
811
+ break;
812
case "Description":
813
packageName = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
814
break;
@@ -838,6 +847,16 @@ namespace WixToolset.Core
847
});
848
}
849
850
+ if (null != comments)
851
+ {
852
+ isCommentsSet = true;
853
+ this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
854
+ {
855
+ PropertyId = SummaryInformationType.Comments,
856
+ Value = comments
857
+ });
858
+ }
859
+
860
if (null != packageName)
861
{
862
isPackageNameSet = true;
src/wix/test/WixToolsetTest.CoreIntegration/CommentsFixture.cs
new
+160
@@ -0,0 +1,160 @@
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 WixToolset.Data;
10
+ using WixToolset.Data.Symbols;
11
+ using WixToolset.Data.WindowsInstaller;
12
+ using Xunit;
13
+
14
+ public class CommentsFixture
15
+ {
16
+ [Fact]
17
+ public void PackageNoSummaryInformation()
18
+ {
19
+ var propertyRows = BuildPackageAndQuerySummaryInformation("PackageNoSummaryInformation.wxs");
20
+
21
+ WixAssert.CompareLineByLine(new[]
22
+ {
23
+ "_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
24
+ }, propertyRows);
25
+ }
26
+
27
+ [Fact]
28
+ public void PackageDefaultComments()
29
+ {
30
+ var propertyRows = BuildPackageAndQuerySummaryInformation("PackageDefault.wxs");
31
+
32
+ WixAssert.CompareLineByLine(new[]
33
+ {
34
+ "_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
35
+ }, propertyRows);
36
+ }
37
+
38
+ [Fact]
39
+ public void PackageEmptyCommentsThrows()
40
+ {
41
+ var exception = Assert.Throws<WixException>(() => BuildPackageAndQuerySummaryInformation("PackageEmpty.wxs"));
42
+ WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
43
+ }
44
+
45
+ [Fact]
46
+ public void PackageCustomComments()
47
+ {
48
+ var propertyRows = BuildPackageAndQuerySummaryInformation("PackageCustom.wxs");
49
+
50
+ WixAssert.CompareLineByLine(new[]
51
+ {
52
+ "_SummaryInformation:Comments\tExample comments"
53
+ }, propertyRows);
54
+ }
55
+
56
+ [Fact]
57
+ public void ModuleNoSummaryInformation()
58
+ {
59
+ var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleNoSummaryInformation.wxs");
60
+
61
+ WixAssert.CompareLineByLine(new[]
62
+ {
63
+ "_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
64
+ }, propertyRows);
65
+ }
66
+
67
+ [Fact]
68
+ public void ModuleDefaultComments()
69
+ {
70
+ var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleDefault.wxs");
71
+
72
+ WixAssert.CompareLineByLine(new[]
73
+ {
74
+ "_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
75
+ }, propertyRows);
76
+ }
77
+
78
+ [Fact]
79
+ public void ModuleEmptyCommentsThrows()
80
+ {
81
+ var exception = Assert.Throws<WixException>(() => BuildModuleAndQuerySummaryInformation("ModuleEmpty.wxs"));
82
+ WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
83
+ }
84
+
85
+ [Fact]
86
+ public void ModuleCustomComments()
87
+ {
88
+ var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleCustom.wxs");
89
+
90
+ WixAssert.CompareLineByLine(new[]
91
+ {
92
+ "_SummaryInformation:Comments\tExample comments"
93
+ }, propertyRows);
94
+ }
95
+
96
+ private static string[] BuildPackageAndQuerySummaryInformation(string file)
97
+ {
98
+ var folder = TestData.Get("TestData", "Comments");
99
+
100
+ using (var fs = new DisposableFileSystem())
101
+ {
102
+ var baseFolder = fs.GetFolder();
103
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
104
+ var binFolder = Path.Combine(baseFolder, "bin");
105
+ var msiPath = Path.Combine(binFolder, "test.msi");
106
+
107
+ var result = WixRunner.Execute(new[]
108
+ {
109
+ "build",
110
+ Path.Combine(folder, file),
111
+ "-intermediateFolder", intermediateFolder,
112
+ "-bindpath", folder,
113
+ "-o", msiPath,
114
+ });
115
+
116
+ if(result.ExitCode != 0)
117
+ {
118
+ throw new WixException(result.Messages.First());
119
+ }
120
+
121
+ return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" })
122
+ .Where(s => s.StartsWith("_SummaryInformation:Comments"))
123
+ .OrderBy(s => s)
124
+ .ToArray();
125
+ }
126
+ }
127
+
128
+ private static string[] BuildModuleAndQuerySummaryInformation(string file)
129
+ {
130
+ var folder = TestData.Get("TestData", "Comments");
131
+
132
+ using (var fs = new DisposableFileSystem())
133
+ {
134
+ var baseFolder = fs.GetFolder();
135
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
136
+ var binFolder = Path.Combine(baseFolder, "bin");
137
+ var msmPath = Path.Combine(binFolder, "test.msm");
138
+
139
+ var result = WixRunner.Execute(new[]
140
+ {
141
+ "build",
142
+ Path.Combine(folder, file),
143
+ "-intermediateFolder", intermediateFolder,
144
+ "-bindpath", Path.Combine(folder, "data"),
145
+ "-o", msmPath,
146
+ });
147
+
148
+ if (result.ExitCode != 0)
149
+ {
150
+ throw new WixException(result.Messages.First());
151
+ }
152
+
153
+ return Query.QueryDatabase(msmPath, new[] { "Property", "_SummaryInformation" })
154
+ .Where(s => s.StartsWith("_SummaryInformation:Comments"))
155
+ .OrderBy(s => s)
156
+ .ToArray();
157
+ }
158
+ }
159
+ }
160
+}
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/ModuleCustom.wxs
new
+16
@@ -0,0 +1,16 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Module
3
+ Id="Module"
4
+ Language="1033"
5
+ Version="1.0.0.0"
6
+ Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
7
+ <SummaryInformation Comments="Example comments" />
8
+
9
+ <Directory Id="ModuleFolder">
10
+ <Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
11
+ <File Id="File1" Name="file.txt" Source="test.txt" />
12
+ </Component>
13
+ </Directory>
14
+
15
+ </Module>
16
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/ModuleDefault.wxs
new
+16
@@ -0,0 +1,16 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Module
3
+ Id="Module"
4
+ Language="1033"
5
+ Version="1.0.0.0"
6
+ Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
7
+ <SummaryInformation />
8
+
9
+ <Directory Id="ModuleFolder">
10
+ <Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
11
+ <File Id="File1" Name="file.txt" Source="test.txt" />
12
+ </Component>
13
+ </Directory>
14
+
15
+ </Module>
16
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/ModuleEmpty.wxs
new
+16
@@ -0,0 +1,16 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Module
3
+ Id="Module"
4
+ Language="1033"
5
+ Version="1.0.0.0"
6
+ Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
7
+ <SummaryInformation Comments="" />
8
+
9
+ <Directory Id="ModuleFolder">
10
+ <Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
11
+ <File Id="File1" Name="file.txt" Source="test.txt" />
12
+ </Component>
13
+ </Directory>
14
+
15
+ </Module>
16
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/ModuleNoSummaryInformation.wxs
new
+15
@@ -0,0 +1,15 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Module
3
+ Id="Module"
4
+ Language="1033"
5
+ Version="1.0.0.0"
6
+ Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
7
+
8
+ <Directory Id="ModuleFolder">
9
+ <Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
10
+ <File Id="File1" Name="file.txt" Source="test.txt" />
11
+ </Component>
12
+ </Directory>
13
+
14
+ </Module>
15
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/PackageCustom.wxs
new
+9
@@ -0,0 +1,9 @@
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
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
7
+ <SummaryInformation Comments="Example comments" />
8
+ </Package>
9
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/PackageDefault.wxs
new
+9
@@ -0,0 +1,9 @@
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
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
7
+ <SummaryInformation />
8
+ </Package>
9
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/PackageEmpty.wxs
new
+9
@@ -0,0 +1,9 @@
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
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
7
+ <SummaryInformation Comments="" />
8
+ </Package>
9
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/PackageNoSummaryInformation.wxs
new
+8
@@ -0,0 +1,8 @@
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
+ <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
7
+ </Package>
8
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Comments/data/test.txt
new
+1
@@ -0,0 +1 @@
1
+This is test.txt.
\ No newline at end of file