Skip to content

Commit

Permalink
Allow custom package comments
Browse files Browse the repository at this point in the history
Fixes #7369
  • Loading branch information
mosBrkr committed Apr 24, 2023
1 parent eadea8a commit f379b72
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wix/WixToolset.Core/Compiler_Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private void ParsePackageElement(XElement node)
var compressed = YesNoDefaultType.Default;
var sourceBits = 0;
string codepage = null;
string comments = null;
var productCode = "*";
string productLanguage = null;
var isPerMachine = true;
Expand Down Expand Up @@ -55,6 +56,9 @@ private void ParsePackageElement(XElement node)
case "Codepage":
codepage = this.Core.GetAttributeLocalizableCodePageValue(sourceLineNumbers, attrib);
break;
case "Comments":
comments = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
break;
case "Compressed":
compressed = this.Core.GetAttributeYesNoDefaultValue(sourceLineNumbers, attrib);
break;
Expand Down Expand Up @@ -193,7 +197,7 @@ private void ParsePackageElement(XElement node)
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
{
PropertyId = SummaryInformationType.Comments,
Value = String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
Value = comments ?? String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
});

this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, productLanguage);
Expand Down
75 changes: 75 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/CommentsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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 WixToolset.Data;
using Xunit;

public class CommentsFixture
{
[Fact]
public void DefaultComments()
{
var propertyRows = BuildAndQuerySummaryInformation("Default.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
}, propertyRows);
}

[Fact]
public void EmptyCommentsThrows()
{
var exception = Assert.Throws<WixException>(() => BuildAndQuerySummaryInformation("Empty.wxs"));
WixAssert.StringEqual("The Package/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
}

[Fact]
public void CustomComments()
{
var propertyRows = BuildAndQuerySummaryInformation("Custom.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tExample comments"
}, propertyRows);
}

private static string[] BuildAndQuerySummaryInformation(string file)
{
var folder = TestData.Get("TestData", "Comments");

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,
});

if(result.ExitCode != 0)
{
throw new WixException(result.Messages.First());
}

return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" })
.Where(s => s.StartsWith("_SummaryInformation:Comments"))
.OrderBy(s => s)
.ToArray();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
Comments="Example comments">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
Comments="">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
</Package>
</Wix>

0 comments on commit f379b72

Please sign in to comment.