From ec6b93c7d601db880d0765fe12abb07a5ec2928e Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Wed, 28 Sep 2022 11:22:23 +0200 Subject: 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. --- src/ext/UI/wixext/UICompiler.cs | 60 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/ext/UI/wixext/UICompiler.cs b/src/ext/UI/wixext/UICompiler.cs index 44ab4cdc..6fdb5bd9 100644 --- a/src/ext/UI/wixext/UICompiler.cs +++ b/src/ext/UI/wixext/UICompiler.cs @@ -16,6 +16,11 @@ namespace WixToolset.UI { public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/ui"; + /// + /// Flag to prevent custom action symbols duplication. + /// + private bool customActionsAdded = false; + /// /// Processes an element for the Compiler. /// @@ -88,33 +93,38 @@ namespace WixToolset.UI { this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, id); - // Because these custom actions are "scheduled" via `DoAction` control events, we have to create the - // custom action definitions here, so the `DoAction` references are static and the targets are - // dynamically created to properly reflect the platform-specific DLL and avoid having duplicate ids - // in the UI .wixlib. - var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString(); - var source = $"WixUiCa_{platform}"; - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Binary, source); - - section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIPrintEula")) + if (!customActionsAdded) { - TargetType = CustomActionTargetType.Dll, - Target = "PrintEula", - SourceType = CustomActionSourceType.Binary, - Source = source, - IgnoreResult = true, - ExecutionType = CustomActionExecutionType.Immediate, - }); + // Because these custom actions are "scheduled" via `DoAction` control events, we have to create the + // custom action definitions here, so the `DoAction` references are static and the targets are + // dynamically created to properly reflect the platform-specific DLL and avoid having duplicate ids + // in the UI .wixlib. + var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString(); + var source = $"WixUiCa_{platform}"; + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Binary, source); - section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIValidatePath")) - { - TargetType = CustomActionTargetType.Dll, - Target = "ValidatePath", - SourceType = CustomActionSourceType.Binary, - Source = source, - IgnoreResult = true, - ExecutionType = CustomActionExecutionType.Immediate, - }); + section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIPrintEula")) + { + TargetType = CustomActionTargetType.Dll, + Target = "PrintEula", + SourceType = CustomActionSourceType.Binary, + Source = source, + IgnoreResult = true, + ExecutionType = CustomActionExecutionType.Immediate, + }); + + section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIValidatePath")) + { + TargetType = CustomActionTargetType.Dll, + Target = "ValidatePath", + SourceType = CustomActionSourceType.Binary, + Source = source, + IgnoreResult = true, + ExecutionType = CustomActionExecutionType.Immediate, + }); + + customActionsAdded = true; + } if (installDirectory != null) { -- cgit v1.2.3-55-g6feb