Skip to content

Commit

Permalink
- Added Compiler.PreferredComponentGuidConsistency to allow consist…
Browse files Browse the repository at this point in the history
…ent generation of the component GUIDs between all versions of the same product.
  • Loading branch information
oleg-shilo committed Oct 27, 2024
1 parent 0df1606 commit 787bcd8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
23 changes: 23 additions & 0 deletions Source/src/WixSharp/AutoElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ public enum CompilerSupportState
Disabled = 1
}

/// <summary>
/// The consistency level of the auto-generated Component GUIDs.
/// </summary>
public enum ComponentGuidConsistency
{
/// <summary>
/// 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.
/// </summary>
WithinSingleVersion,

/// <summary>
/// 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.
/// </summary>
WithinAllVersions,

/// <summary>
/// The components' GUIDs are always unique. Every build will trigger the regeneration of all components GUIDs.
/// </summary>
AlwaysUnique,
}

/// <summary>
/// Automatically insert elements required for satisfy odd MSI restrictions.
/// <para>- You must set KeyPath you install in the user profile.</para>
Expand Down
6 changes: 5 additions & 1 deletion Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ static void EnsureVSIntegration()
/// </summary>
static public bool PreserveDbgFiles = false;

/// <summary>
/// The preferred consistency level of the auto-generated Component GUIDs.
/// </summary>
static public ComponentGuidConsistency PreferredComponentGuidConsistency = ComponentGuidConsistency.WithinAllVersions;
/// <summary>
/// Indicates whether compiler should emit relative or absolute paths in the WiX XML source.
/// </summary>
Expand Down Expand Up @@ -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))));
}

Expand Down
16 changes: 14 additions & 2 deletions Source/src/WixSharp/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ THE SOFTWARE.
using System.Globalization;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using WixSharp.CommonTasks;

namespace WixSharp
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions Source/src/WixSharp/WixGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ static void PrintOrderMap()
/// <returns></returns>
static public Guid NewGuid()
{
//if (ConsistentGenerationStartValue != null)
// return ConsistentGenerationStartValue++;
//else
// return Guid.NewGuid();
var seed = rnd.Next(int.MaxValue);
return Generator(seed);
}
Expand Down Expand Up @@ -292,7 +288,9 @@ public static Guid Sequential(object seed)
/// <returns></returns>
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;
}
}
}

0 comments on commit 787bcd8

Please sign in to comment.