From 787bcd82c9eb0315219203c340c1da35280d4f98 Mon Sep 17 00:00:00 2001 From: Oleg Shilo Date: Sun, 27 Oct 2024 23:57:19 +1100 Subject: [PATCH] - Added `Compiler.PreferredComponentGuidConsistency` to allow consistent generation of the component GUIDs between all versions of the same product. --- Source/src/WixSharp/AutoElements.cs | 23 +++++++++++++++++++++++ Source/src/WixSharp/Compiler.cs | 6 +++++- Source/src/WixSharp/Project.cs | 16 ++++++++++++++-- Source/src/WixSharp/WixGuid.cs | 8 +++----- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Source/src/WixSharp/AutoElements.cs b/Source/src/WixSharp/AutoElements.cs index 6941bf0d..c743df49 100644 --- a/Source/src/WixSharp/AutoElements.cs +++ b/Source/src/WixSharp/AutoElements.cs @@ -56,6 +56,29 @@ public enum CompilerSupportState Disabled = 1 } + /// + /// The consistency level of the auto-generated Component GUIDs. + /// + public enum ComponentGuidConsistency + { + /// + /// The components' GUIDs are consistent (unchanged) within a single version of the product setup builds. + /// The increment in the version will trigger the regeneration of all components GUIDs. + /// + WithinSingleVersion, + + /// + /// The components' GUIDs are consistent (unchanged) across all versions of the product setup builds. + /// The increment in the version will not trigger the regeneration of all components GUIDs. + /// + WithinAllVersions, + + /// + /// The components' GUIDs are always unique. Every build will trigger the regeneration of all components GUIDs. + /// + AlwaysUnique, + } + /// /// Automatically insert elements required for satisfy odd MSI restrictions. /// - You must set KeyPath you install in the user profile. diff --git a/Source/src/WixSharp/Compiler.cs b/Source/src/WixSharp/Compiler.cs index fa9466d7..54b0f9c9 100644 --- a/Source/src/WixSharp/Compiler.cs +++ b/Source/src/WixSharp/Compiler.cs @@ -453,6 +453,10 @@ static void EnsureVSIntegration() /// static public bool PreserveDbgFiles = false; + /// + /// The preferred consistency level of the auto-generated Component GUIDs. + /// + static public ComponentGuidConsistency PreferredComponentGuidConsistency = ComponentGuidConsistency.WithinAllVersions; /// /// Indicates whether compiler should emit relative or absolute paths in the WiX XML source. /// @@ -2743,7 +2747,7 @@ static void ProcessCustomActions(Project wProject, XElement product) if (wAction.RollbackProgressText != null) { uis.ForEach(ui => - ui.Add(new XElement("ProgressText", new XAttribute("Value", wAction.RollbackProgressText), + ui.Add(new XElement("ProgressText", new XAttribute("Value", wAction.RollbackProgressText), new XAttribute("Action", roollbackActionId)))); } diff --git a/Source/src/WixSharp/Project.cs b/Source/src/WixSharp/Project.cs index 619cb8ef..69333f7d 100644 --- a/Source/src/WixSharp/Project.cs +++ b/Source/src/WixSharp/Project.cs @@ -32,7 +32,6 @@ THE SOFTWARE. using System.Globalization; using System.Linq; using System.Text; -using System.Xml.Linq; using WixSharp.CommonTasks; namespace WixSharp @@ -400,7 +399,20 @@ public Guid? GUID internal void ResetWixGuidStartValue() { - WixGuid.ConsistentGenerationStartValue = this.ProductId ?? this.GUID ?? Guid.NewGuid(); + switch (Compiler.PreferredComponentGuidConsistency) + { + case ComponentGuidConsistency.WithinSingleVersion: + WixGuid.ConsistentGenerationStartValue = this.ProductId ?? this.GUID ?? Guid.NewGuid(); + break; + + case ComponentGuidConsistency.WithinAllVersions: + WixGuid.ConsistentGenerationStartValue = this.UpgradeCode ?? this.GUID ?? Guid.NewGuid(); + break; + + default: + WixGuid.ConsistentGenerationStartValue = Guid.NewGuid(); + break; + } } internal void ResetAutoIdGeneration(bool supressWarning) diff --git a/Source/src/WixSharp/WixGuid.cs b/Source/src/WixSharp/WixGuid.cs index 21f4e947..9c462ef1 100644 --- a/Source/src/WixSharp/WixGuid.cs +++ b/Source/src/WixSharp/WixGuid.cs @@ -200,10 +200,6 @@ static void PrintOrderMap() /// static public Guid NewGuid() { - //if (ConsistentGenerationStartValue != null) - // return ConsistentGenerationStartValue++; - //else - // return Guid.NewGuid(); var seed = rnd.Next(int.MaxValue); return Generator(seed); } @@ -292,7 +288,9 @@ public static Guid Sequential(object seed) /// public static Guid Default(object seed) { - return WixGuid.HashGuidByInteger(WixGuid.ConsistentGenerationStartValue.CurrentGuid, seed.ToString().GetHashCode32()); + Guid result = WixGuid.HashGuidByInteger(WixGuid.ConsistentGenerationStartValue.CurrentGuid, seed.ToString().GetHashCode32()); + // Debug.WriteLine($"{seed}: {result}"); + return result; } } } \ No newline at end of file