Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Package Id and Bundle Id attribute that can replace UpgradeCodes #584

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/setup/ThmViewerPackage/ThmViewerPackage.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- 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. -->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="WiX Toolset Theme Viewer" Manufacturer="WiX Toolset" Language="1033" Version="!(bind.fileVersion.ThmViewerFile)" UpgradeCode="59c4b122-5167-445b-8fc4-09dcd4eced89">
<Package Id="WixToolset.ThemeViewer.Package" Name="WiX Toolset Theme Viewer" Manufacturer="WiX Toolset" Language="1033" Version="!(bind.fileVersion.ThmViewerFile)">
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

<Feature Id="Main">
Expand Down
2 changes: 1 addition & 1 deletion src/setup/WixAdditionalTools/WixAdditionalTools.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
<Bundle Name="!(loc.Name)" Manufacturer="WiX Toolset" Version="$(SetupVersion)" UpgradeCode="fc48131d-214a-439b-9a31-ef2ea5c69ea5"
<Bundle Id="WixToolset.WixAdditionalTools" Name="!(loc.Name)" Manufacturer="WiX Toolset" Version="$(SetupVersion)"
AboutUrl="!(loc.AboutUrl)" HelpUrl="!(loc.SupportUrl)" UpdateUrl="!(loc.UpdateUrl)">
<BootstrapperApplication>
<bal:WixStandardBootstrapperApplication
Expand Down
2 changes: 1 addition & 1 deletion src/setup/wix-cli/Package.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- 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. -->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="WiX Toolset Command-Line Tools" Manufacturer="WiX Toolset" Version="!(bind.fileVersion.WixExe)" UpgradeCode="2e85dc76-769f-46d2-82a7-46cb3a0c9d50">
<Package Id="WixToolset.CommandLineTools.Package" Name="WiX Toolset Command-Line Tools" Manufacturer="WiX Toolset" Version="!(bind.fileVersion.WixExe)">
<MediaTemplate EmbedCab="yes" />

<ComponentGroupRef Id="BinaryFiles" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6216,6 +6216,9 @@ private void DecompilePropertyTable(Table table)
case "Manufacturer":
this.DecompilerHelper.RootElement.SetAttributeValue("Manufacturer", value);
continue;
case "PackageId":
this.DecompilerHelper.RootElement.SetAttributeValue("Id", value);
continue;
case "ProductCode":
this.DecompilerHelper.RootElement.SetAttributeValue("ProductCode", value.ToUpper(CultureInfo.InvariantCulture));
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/wix/WixToolset.Core/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ internal partial class Compiler : ICompiler
private const char ComponentIdPlaceholderEnd = (char)167;
private Dictionary<string, string> componentIdPlaceholders;

// As outlined in RFC 4122, this is our namespace for generating name-based (version 3) UUIDs for upgrade codes.
private static readonly Guid UpgradeCodeGuidNamespace = new Guid("{D9C5E8D9-0F97-4D24-A235-91BD2FA169A6}");

// If these are true you know you are building a module or product
// but if they are false you cannot not be sure they will not end
// up a product or module. Use these flags carefully.
Expand Down
17 changes: 14 additions & 3 deletions src/wix/WixToolset.Core/Compiler_Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private void ParseApprovedExeForElevation(XElement node)
private void ParseBundleElement(XElement node)
{
var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
Identifier id = null;
string copyright = null;
string aboutUrl = null;
var modifyType = WixBundleModifyType.Allowed;
Expand Down Expand Up @@ -144,6 +145,9 @@ private void ParseBundleElement(XElement node)
{
switch (attrib.Name.LocalName)
{
case "Id":
id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib);
break;
case "AboutUrl":
aboutUrl = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
break;
Expand Down Expand Up @@ -233,7 +237,14 @@ private void ParseBundleElement(XElement node)

if (String.IsNullOrEmpty(upgradeCode))
{
this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "UpgradeCode"));
if (id is null)
{
this.Core.Write(ErrorMessages.ExpectedAttributes(sourceLineNumbers, node.Name.LocalName, "Id", "UpgradeCode"));
}
else
{
upgradeCode = this.Core.CreateGuid(Compiler.UpgradeCodeGuidNamespace, id.Id);
}
}

if (String.IsNullOrEmpty(copyright))
Expand Down Expand Up @@ -265,7 +276,7 @@ private void ParseBundleElement(XElement node)
logVariablePrefixAndExtension = String.Concat("WixBundleLog:", fileSystemSafeBundleName, ":log");
}

this.activeName = String.IsNullOrEmpty(name) ? Common.GenerateGuid() : name;
this.activeName = String.IsNullOrEmpty(name) ? String.IsNullOrEmpty(id?.Id) ? Common.GenerateGuid() : id.Id : name;
this.Core.CreateActiveSection(this.activeName, SectionType.Bundle, this.Context.CompilationId);

// Now that the active section is initialized, process only extension attributes and the special ProviderKey attribute.
Expand Down Expand Up @@ -401,7 +412,7 @@ private void ParseBundleElement(XElement node)

if (!this.Core.EncounteredError)
{
var symbol = this.Core.AddSymbol(new WixBundleSymbol(sourceLineNumbers)
var symbol = this.Core.AddSymbol(new WixBundleSymbol(sourceLineNumbers, id)
{
UpgradeCode = upgradeCode,
Version = version,
Expand Down
20 changes: 18 additions & 2 deletions src/wix/WixToolset.Core/Compiler_Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal partial class Compiler : ICompiler
private void ParsePackageElement(XElement node)
{
var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
Identifier id = null;
var compressed = YesNoDefaultType.Default;
var sourceBits = 0;
string codepage = null;
Expand Down Expand Up @@ -53,6 +54,9 @@ private void ParsePackageElement(XElement node)
{
switch (attrib.Name.LocalName)
{
case "Id":
id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib);
break;
case "Codepage":
codepage = this.Core.GetAttributeLocalizableCodePageValue(sourceLineNumbers, attrib);
break;
Expand Down Expand Up @@ -156,7 +160,14 @@ private void ParsePackageElement(XElement node)

if (null == upgradeCode)
{
this.Core.Write(WarningMessages.MissingUpgradeCode(sourceLineNumbers));
if (id is null)
{
this.Core.Write(WarningMessages.MissingUpgradeCode(sourceLineNumbers));
}
else
{
upgradeCode = this.Core.CreateGuid(Compiler.UpgradeCodeGuidNamespace, id.Id);
}
}

if (null == version)
Expand All @@ -179,6 +190,11 @@ private void ParsePackageElement(XElement node)
this.compilingProduct = true;
this.Core.CreateActiveSection(productCode, SectionType.Package, this.Context.CompilationId);

if (null != id)
robmen marked this conversation as resolved.
Show resolved Hide resolved
{
this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "PackageId"), id.Id, false, false, false, true);
}

this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "Manufacturer"), manufacturer, false, false, false, true);
this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ProductCode"), productCode, false, false, false, true);
this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "ProductLanguage"), productLanguage, false, false, false, true);
Expand Down Expand Up @@ -392,7 +408,7 @@ private void ParsePackageElement(XElement node)

if (!this.Core.EncounteredError)
{
this.Core.AddSymbol(new WixPackageSymbol(sourceLineNumbers)
this.Core.AddSymbol(new WixPackageSymbol(sourceLineNumbers, id)
{
PackageId = productCode,
UpgradeCode = upgradeCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void CanBuildBundleWithAllUsersPackage()
var packageElements = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPackageProperties", ignoreAttributesByElementName);
WixAssert.CompareLineByLine(new[]
{
"<WixPackageProperties Package='test.msi' Vital='yes' DisplayName='All Users Package' DownloadSize='*' PackageSize='*' InstalledSize='28' PackageType='Msi' Permanent='no' LogPathVariable='WixBundleLog_test.msi' RollbackLogPathVariable='WixBundleRollbackLog_test.msi' Compressed='no' ProductCode='{33333333-3333-3333-3333-333333333333}' UpgradeCode='{4BE34BEE-CA23-488E-96A0-B15878E3654B}' Version='1.0' Cache='keep' />",
"<WixPackageProperties Package='test.msi' Vital='yes' DisplayName='All Users Package' DownloadSize='*' PackageSize='*' InstalledSize='28' PackageType='Msi' Permanent='no' LogPathVariable='WixBundleLog_test.msi' RollbackLogPathVariable='WixBundleRollbackLog_test.msi' Compressed='no' ProductCode='{33333333-3333-3333-3333-333333333333}' UpgradeCode='{C00D7E9A-1276-51ED-B782-A20AB34D4070}' Version='1.0' Cache='keep' />",
}, packageElements);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/wix/test/WixToolsetTest.CoreIntegration/ContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ public void HarvestedPayloadsArePutInCorrectPackage()
var msiPackages = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:MsiPackage", ignoreAttributes);
WixAssert.CompareLineByLine(new[]
{
"<MsiPackage Id='FirstX86.msi' Cache='keep' CacheId='*' InstallSize='*' Size='*' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' LogPathVariable='WixBundleLog_FirstX86.msi' RollbackLogPathVariable='WixBundleRollbackLog_FirstX86.msi' ProductCode='*' Language='1033' Version='1.0.0.0' UpgradeCode='{12E4699F-E774-4D05-8A01-5BDD41BBA127}'>" +
"<MsiPackage Id='FirstX86.msi' Cache='keep' CacheId='*' InstallSize='*' Size='*' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' LogPathVariable='WixBundleLog_FirstX86.msi' RollbackLogPathVariable='WixBundleRollbackLog_FirstX86.msi' ProductCode='*' Language='1033' Version='1.0.0.0' UpgradeCode='{C00D7E9A-1276-51ED-B782-A20AB34D4070}'>" +
"<MsiProperty Id='MSIFASTINSTALL' Value='1' />" +
"<MsiProperty Id='ARPSYSTEMCOMPONENT' Value='1' />" +
$"<Provides Key='{GetProductCodeFromMsiPdb(pdbPaths[0])}_v1.0.0.0' Version='1.0.0.0' DisplayName='MsiPackage' />" +
"<RelatedPackage Id='{12E4699F-E774-4D05-8A01-5BDD41BBA127}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{12E4699F-E774-4D05-8A01-5BDD41BBA127}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{C00D7E9A-1276-51ED-B782-A20AB34D4070}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{C00D7E9A-1276-51ED-B782-A20AB34D4070}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<PayloadRef Id='FirstX86.msi' />" +
"<PayloadRef Id='fk1m38Cf9RZ2Bx_ipinRY6BftelU' />" +
"</MsiPackage>",
"<MsiPackage Id='FirstX64.msi' Cache='keep' CacheId='*' InstallSize='*' Size='*' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryBackward='WixDefaultBoundary' LogPathVariable='WixBundleLog_FirstX64.msi' RollbackLogPathVariable='WixBundleRollbackLog_FirstX64.msi' ProductCode='*' Language='1033' Version='1.0.0.0' UpgradeCode='{12E4699F-E774-4D05-8A01-5BDD41BBA127}'>" +
"<MsiPackage Id='FirstX64.msi' Cache='keep' CacheId='*' InstallSize='*' Size='*' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryBackward='WixDefaultBoundary' LogPathVariable='WixBundleLog_FirstX64.msi' RollbackLogPathVariable='WixBundleRollbackLog_FirstX64.msi' ProductCode='*' Language='1033' Version='1.0.0.0' UpgradeCode='{C00D7E9A-1276-51ED-B782-A20AB34D4070}'>" +
"<MsiProperty Id='ARPSYSTEMCOMPONENT' Value='1' />" +
"<MsiProperty Id='MSIFASTINSTALL' Value='7' />" +
$"<Provides Key='{GetProductCodeFromMsiPdb(pdbPaths[1])}_v1.0.0.0' Version='1.0.0.0' DisplayName='MsiPackage' />" +
"<RelatedPackage Id='{12E4699F-E774-4D05-8A01-5BDD41BBA127}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{12E4699F-E774-4D05-8A01-5BDD41BBA127}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{C00D7E9A-1276-51ED-B782-A20AB34D4070}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<RelatedPackage Id='{C00D7E9A-1276-51ED-B782-A20AB34D4070}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
"<PayloadRef Id='FirstX64.msi' />" +
"<PayloadRef Id='fC0n41rZK8oW3JK8LzHu6AT3CjdQ' />" +
"</MsiPackage>",
Expand Down
18 changes: 10 additions & 8 deletions src/wix/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace WixToolsetTest.CoreIntegration
{
using System;
using System.IO;
using System.Linq;
using Example.Extension;
using WixInternal.TestSupport;
using WixInternal.Core.TestPackage;
using WixInternal.TestSupport;
using Xunit;

public class MsiQueryFixture
Expand Down Expand Up @@ -929,16 +927,20 @@ public void PopulatesUpgradeTableFromDetectOnlyUpgrade()
result.AssertSuccess();

Assert.True(File.Exists(msiPath));
var results = Query.QueryDatabase(msiPath, new[] { "Upgrade" });
var results = Query.QueryDatabase(msiPath, new[] { "Property", "Upgrade" });
var upgradeRows = results.Where(r => r.StartsWith("Upgrade:")).OrderBy(s => s).ToArray();
WixAssert.CompareLineByLine(new[]
{
"Upgrade:{12E4699F-E774-4D05-8A01-5BDD41BBA127}\t\t1.0.0.0\t1033\t1\t\tWIX_UPGRADE_DETECTED",
"Upgrade:{12E4699F-E774-4D05-8A01-5BDD41BBA127}\t1.0.0.0\t\t1033\t2\t\tWIX_DOWNGRADE_DETECTED",
"Upgrade:{B05772EA-82B8-4DE0-B7EB-45B5F0CCFE6D}\t1.0.0\t\t\t256\t\tRELPRODFOUND",
}, results);
"Upgrade:{C00D7E9A-1276-51ED-B782-A20AB34D4070}\t\t1.0.0.0\t1033\t1\t\tWIX_UPGRADE_DETECTED",
"Upgrade:{C00D7E9A-1276-51ED-B782-A20AB34D4070}\t1.0.0.0\t\t1033\t2\t\tWIX_DOWNGRADE_DETECTED",
}, upgradeRows);

var packageId = results.Where(r => r.StartsWith("Property:PackageId\t")).Single();
Assert.Equal("Property:PackageId\tWixToolsetTest.TestPackage", packageId);

var prefix = "Property:SecureCustomProperties\t";
var secureProperties = Query.QueryDatabase(msiPath, new[] { "Property" }).Where(p => p.StartsWith(prefix)).Single();
var secureProperties = results.Where(p => p.StartsWith(prefix)).Single();
WixAssert.CompareLineByLine(new[]
{
"RELPRODFOUND",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Duplicate Cross Fragment Reference" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.Duplicate.Cross.Fragment.Reference" Name="Duplicate Cross Fragment Reference" Version="1.0.0.0" Manufacturer="Example Corporation">
<DirectoryRef Id="TestFolder" />
</Package>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.DuplicatedOverrideVirtualSymbol" Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation">

<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="override TestFolder" Name="Override Test Folder" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.DuplicatedOverrideVirtualSymbol" Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation">

<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="override TestFolder" Name="Override Test Folder" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.DuplicatedOverrideVirtualSymbol" Name="Duplicated Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation">

<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="virtual TestFolder" Name="First Virtual Test Folder" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Has Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.HasVirtualSymbol" Name="Has Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation">
<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="virtual TestFolder" Name="Test Folder" />
</StandardDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Invalid Cross Fragment Reference" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.InvalidCrossFragmentReference" Name="Invalid Cross Fragment Reference" Version="1.0.0.0" Manufacturer="Example Corporation">
<DirectoryRef Id="Foo" />
</Package>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Id="WixToolsetTest.OverrideVirtualSymbol" Name="Override Virtual Symbol" Version="1.0.0.0" Manufacturer="Example Corporation">

<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="override TestFolder" Name="Override Test Folder" />
Expand Down
Loading