Skip to content

Commit

Permalink
Support WiX3-compantible auto-guids for registry key path
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbar committed Jan 14, 2025
1 parent b5e9edf commit 79ed5db
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ This repository contains the PanelSwWix4: A custom WiX Toolset codebase
- Support sending custom messages on embedded pipe
- Best effort to log premature termination of companion process
- Monitor UX folder and re-extract any UX payloads that were deleted for any reason
- Reorder cache actions: moves non-executing package caching to the end of the plan. This optimizes run time as packages that are cached but not executed will not stand in the way of executing packages.
- Reorder cache actions: moves non-executing package caching to the end of the plan. This optimizes run time as packages that are cached but not executed will not stand in the way of executing packages.
- [8896](https://github.com/wixtoolset/issues/issues/8896): Component/@WiX3CompatibleGuid- Support WiX3-compantible auto-guids for registry key path
10 changes: 9 additions & 1 deletion src/api/wix/WixToolset.Data/Symbols/ComponentSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static partial class SymbolDefinitions
new IntermediateFieldDefinition(nameof(ComponentSymbolFields.Condition), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(ComponentSymbolFields.KeyPath), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(ComponentSymbolFields.KeyPathType), IntermediateFieldType.Number),
new IntermediateFieldDefinition(nameof(ComponentSymbolFields.WiX3CompatibleGuid), IntermediateFieldType.Bool),
},
typeof(ComponentSymbol));
}
Expand All @@ -47,6 +48,7 @@ public enum ComponentSymbolFields
Condition,
KeyPath,
KeyPathType,
WiX3CompatibleGuid,
}

public enum ComponentLocation
Expand Down Expand Up @@ -151,5 +153,11 @@ public ComponentKeyPathType KeyPathType
get => (ComponentKeyPathType)this.Fields[(int)ComponentSymbolFields.KeyPathType].AsNumber();
set => this.Set((int)ComponentSymbolFields.KeyPathType, (int)value);
}

public bool WiX3CompatibleGuid
{
get => this.Fields[(int)ComponentSymbolFields.WiX3CompatibleGuid].AsBool();
set => this.Set((int)ComponentSymbolFields.WiX3CompatibleGuid, value);
}
}
}
}
6 changes: 6 additions & 0 deletions src/api/wix/WixToolset.Data/WarningMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ public static Message MissingContainerExtension(SourceLineNumber sourceLineNumbe
return Message(sourceLineNumbers, Ids.MissingContainerExtension, "Container '{0}' has BundleExtensionRef set to '{1}', which could not be resolved to a container extension. To extract this container add the missing extension to the extraction command line", containerId, bundleExtensionRef);
}

public static Message AlreadyWiX3CompatibleGuid(SourceLineNumber sourceLineNumbers, ComponentKeyPathType keyPathType)
{
return Message(sourceLineNumbers, Ids.AlreadyWiX3CompatibleGuid, "Components with KeyPath type {0} have WiX3-compatible GUID by default. Attribute WiX3CompatibleGuid is redundant.", keyPathType);
}

private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args)
{
return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, format, args);
Expand Down Expand Up @@ -861,6 +866,7 @@ public enum Ids
ExePackageDetectInformationRecommended = 1161,
InvalidWixVersion = 1162,
MissingContainerExtension = 1163,
AlreadyWiX3CompatibleGuid = 1164,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ private void GenerateComponentGuid(ComponentSymbol componentSymbol)
{
var bitness = componentSymbol.Win64 ? "64" : String.Empty;
var regkey = String.Concat(bitness, registrySymbol.Root, "\\", registrySymbol.Key, "\\", registrySymbol.Name);
if (componentSymbol.WiX3CompatibleGuid)
{
regkey = String.Concat(bitness, (int)registrySymbol.Root, "\\", registrySymbol.Key, "\\", registrySymbol.Name);
}
componentSymbol.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, regkey.ToLowerInvariant());
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/wix/WixToolset.Core/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ private void ParseComponentElement(XElement node, ComplexReferenceParentType par
var location = ComponentLocation.LocalOnly;
var disableRegistryReflection = false;

var wiX3CompatibleGuid = false;
var neverOverwrite = false;
var permanent = false;
var shared = false;
Expand Down Expand Up @@ -2184,6 +2185,9 @@ private void ParseComponentElement(XElement node, ComplexReferenceParentType par
case "Guid":
guid = this.Core.GetAttributeGuidValue(sourceLineNumbers, attrib, true, true);
break;
case "WiX3CompatibleGuid":
wiX3CompatibleGuid = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
break;
case "KeyPath":
if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
{
Expand Down Expand Up @@ -2515,6 +2519,15 @@ private void ParseComponentElement(XElement node, ComplexReferenceParentType par
}
}

if (wiX3CompatibleGuid && (guid != "*"))
{
this.Core.Write(ErrorMessages.IllegalAttributeValueWithoutOtherAttribute(sourceLineNumbers, node.Name.LocalName, "WiX3CompatibleGuid", "yes", "Guid", "*"));
}
if (wiX3CompatibleGuid && (ComponentKeyPathType.Registry != keyPathType))
{
this.Core.Write(WarningMessages.AlreadyWiX3CompatibleGuid(sourceLineNumbers, keyPathType));
}

// finally add the Component table row
if (!this.Core.EncounteredError)
{
Expand All @@ -2534,6 +2547,7 @@ private void ParseComponentElement(XElement node, ComplexReferenceParentType par
Transitive = transitive,
UninstallWhenSuperseded = uninstallWhenSuperseded,
Win64 = win64,
WiX3CompatibleGuid = wiX3CompatibleGuid,
});

if (multiInstance)
Expand Down
31 changes: 31 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@ public void PopulatesAppSearchTablesFromRegistrySearch64()
}
}

[Fact]
public void WiX3CompatibleGuid()
{
var folder = TestData.Get(@"TestData\WiX3CompatibleGuid");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, @"bin\test.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, "Package.wxs"),
Path.Combine(folder, "WiX3CompatibleGuid.wxs"),
"-intermediateFolder", intermediateFolder,
"-o", msiPath
});

result.AssertSuccess();

Assert.True(File.Exists(msiPath));
var results = Query.QueryDatabase(msiPath, new[] { "Component" });

Assert.Equal(2, results.Length);
Assert.Contains(results, component => component.Contains("WiX3CompatibleGuid") && component.Contains("8BAF5399-2FD2-50B6-ABDA-98FB3A5BB148", StringComparison.InvariantCultureIgnoreCase));
Assert.Contains(results, component => component.Contains("WiX4CompatibleGuid") && !component.Contains("8BAF5399-2FD2-50B6-ABDA-98FB3A5BB148", StringComparison.InvariantCultureIgnoreCase));
}
}

[Fact]
public void PopulatesCreateFolderTableForNullKeypathComponents()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="WiX3CompatibleGuid" Codepage="1252" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" Compressed="no" InstallerVersion="200" Scope="perMachine">

<MajorUpgrade DowngradeErrorMessage="Dont care" />

<Feature Id="ProductFeature" Title="Title">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Package>

<Fragment>
<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="WiX3CompatibleGuid" />
</StandardDirectory>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="TARGETDIR">
<!-- Expecting {8BAF5399-2FD2-50B6-ABDA-98FB3A5BB148} -->
<Component Id="WiX3CompatibleGuid" WiX3CompatibleGuid="yes" Bitness="always32" Condition="x=y">
<RegistryValue Root="HKLM" Key="SOFTWARE\WiX3CompatiblityCheck" Name="Test" Value="test value" />
</Component>

<!-- Expecting *not* {8BAF5399-2FD2-50B6-ABDA-98FB3A5BB148} -->
<Component Id="WiX4CompatibleGuid" Bitness="always32" Condition="x=z">
<RegistryValue Root="HKLM" Key="SOFTWARE\WiX3CompatiblityCheck" Name="Test" Value="test value" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>

0 comments on commit 79ed5db

Please sign in to comment.