@joebigelow / wix-1 / commits / ec6b93c7

Fix UICompiler custom actions duplication

For each ui:WixUI tag found, UICompiler adds PrintEula and ValidatePath custom actions. This causes problems with duplicate symbols if 2 or more such tags are used. This change makes sure that UI custom actions are added only once in total.

StefanStojanovic committed Sep 28, 2022 at 11:22 UTC ec6b93c7d601db880d0765fe12abb07a5ec2928e
1 file changed +35 -25
src/ext/UI/wixext/UICompiler.cs
+35 -25
@@ -16,6 +16,11 @@ namespace WixToolset.UI
16 {
17 public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/ui";
18
19 + /// <summary>
20 + /// Flag to prevent custom action symbols duplication.
21 + /// </summary>
22 + private bool customActionsAdded = false;
23 +
24 /// <summary>
25 /// Processes an element for the Compiler.
26 /// </summary>
@@ -88,33 +93,38 @@ namespace WixToolset.UI
93 {
94 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, id);
95
91 - // Because these custom actions are "scheduled" via `DoAction` control events, we have to create the
92 - // custom action definitions here, so the `DoAction` references are static and the targets are
93 - // dynamically created to properly reflect the platform-specific DLL and avoid having duplicate ids
94 - // in the UI .wixlib.
95 - var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString();
96 - var source = $"WixUiCa_{platform}";
97 - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Binary, source);
98 -
99 - section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIPrintEula"))
96 + if (!customActionsAdded)
97 {
101 - TargetType = CustomActionTargetType.Dll,
102 - Target = "PrintEula",
103 - SourceType = CustomActionSourceType.Binary,
104 - Source = source,
105 - IgnoreResult = true,
106 - ExecutionType = CustomActionExecutionType.Immediate,
107 - });
98 + // Because these custom actions are "scheduled" via `DoAction` control events, we have to create the
99 + // custom action definitions here, so the `DoAction` references are static and the targets are
100 + // dynamically created to properly reflect the platform-specific DLL and avoid having duplicate ids
101 + // in the UI .wixlib.
102 + var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString();
103 + var source = $"WixUiCa_{platform}";
104 + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Binary, source);
105
109 - section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIValidatePath"))
110 - {
111 - TargetType = CustomActionTargetType.Dll,
112 - Target = "ValidatePath",
113 - SourceType = CustomActionSourceType.Binary,
114 - Source = source,
115 - IgnoreResult = true,
116 - ExecutionType = CustomActionExecutionType.Immediate,
117 - });
106 + section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIPrintEula"))
107 + {
108 + TargetType = CustomActionTargetType.Dll,
109 + Target = "PrintEula",
110 + SourceType = CustomActionSourceType.Binary,
111 + Source = source,
112 + IgnoreResult = true,
113 + ExecutionType = CustomActionExecutionType.Immediate,
114 + });
115 +
116 + section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIValidatePath"))
117 + {
118 + TargetType = CustomActionTargetType.Dll,
119 + Target = "ValidatePath",
120 + SourceType = CustomActionSourceType.Binary,
121 + Source = source,
122 + IgnoreResult = true,
123 + ExecutionType = CustomActionExecutionType.Immediate,
124 + });
125 +
126 + customActionsAdded = true;
127 + }
128
129 if (installDirectory != null)
130 {