diff --git a/Source/src/WixSharp/Certificate.cs b/Source/src/WixSharp/Certificate.cs index 86af42e0..f438e446 100644 --- a/Source/src/WixSharp/Certificate.cs +++ b/Source/src/WixSharp/Certificate.cs @@ -234,7 +234,11 @@ public void Process(ProcessingContext context) XElement component = this.CreateParentComponent(); component.Add(this.ToXElement(WixExtension.IIs, "Certificate")); - context.XParent.FindFirst("Component").Parent?.Add(component); + + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); MapComponentToFeatures(component.Attribute("Id")?.Value, ActualFeatures, context); } diff --git a/Source/src/WixSharp/EnvironmentVariable.cs b/Source/src/WixSharp/EnvironmentVariable.cs index 152e4798..d3bec9f4 100644 --- a/Source/src/WixSharp/EnvironmentVariable.cs +++ b/Source/src/WixSharp/EnvironmentVariable.cs @@ -172,10 +172,10 @@ public void Process(ProcessingContext context) .AddAttributes(Condition.Attributes)); } - var parent = context.XParent.FindFirstComponentParent() ?? - context.XParent.FindLastDirectory(); + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); - parent?.Add(component); + bestParent.Add(component); MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } diff --git a/Source/src/WixSharp/IniFile.cs b/Source/src/WixSharp/IniFile.cs index 4de27ad8..4cda1d9e 100644 --- a/Source/src/WixSharp/IniFile.cs +++ b/Source/src/WixSharp/IniFile.cs @@ -525,7 +525,11 @@ public void Process(ProcessingContext context) { XElement component = this.CreateParentComponent(); component.Add(this.ToXElement("IniFile")); - context.XParent.FindFirst("Component").Parent?.Add(component); + + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } diff --git a/Source/src/WixSharp/RemoveRegistryKey.cs b/Source/src/WixSharp/RemoveRegistryKey.cs index f5083dbb..04e20ad4 100644 --- a/Source/src/WixSharp/RemoveRegistryKey.cs +++ b/Source/src/WixSharp/RemoveRegistryKey.cs @@ -275,7 +275,11 @@ public void Process(ProcessingContext context) { XElement component = this.CreateParentComponent(); component.Add(this.ToXElement("RemoveRegistryKey")); - context.XParent.FindFirst("Component").Parent?.Add(component); + + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } diff --git a/Source/src/WixSharp/RemoveRegistryValue.cs b/Source/src/WixSharp/RemoveRegistryValue.cs index e9da3a18..ee8d492f 100644 --- a/Source/src/WixSharp/RemoveRegistryValue.cs +++ b/Source/src/WixSharp/RemoveRegistryValue.cs @@ -263,7 +263,11 @@ public void Process(ProcessingContext context) { XElement component = this.CreateParentComponent(); component.Add(this.ToXElement("RemoveRegistryValue")); - context.XParent.FindFirst("Component").Parent?.Add(component); + + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } diff --git a/Source/src/WixSharp/SqlDatabase.cs b/Source/src/WixSharp/SqlDatabase.cs index 6a9cbca4..2a9d067c 100644 --- a/Source/src/WixSharp/SqlDatabase.cs +++ b/Source/src/WixSharp/SqlDatabase.cs @@ -283,7 +283,10 @@ public void Process(ProcessingContext context) item.Process(newContext); } - context.XParent.FindFirst("Component").Parent?.Add(component); + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } else diff --git a/Source/src/WixSharp/SqlScript.cs b/Source/src/WixSharp/SqlScript.cs index ffcd65e9..01cdc434 100644 --- a/Source/src/WixSharp/SqlScript.cs +++ b/Source/src/WixSharp/SqlScript.cs @@ -765,7 +765,11 @@ public void Process(ProcessingContext context) XElement sqlScript = this.ToXElement(WixExtension.Sql, "SqlScript"); component.Add(sqlScript); - context.XParent.FindFirst("Component").Parent?.Add(component); + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); + MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } else diff --git a/Source/src/WixSharp/SqlString.cs b/Source/src/WixSharp/SqlString.cs index c08ea5ec..5e7ab684 100644 --- a/Source/src/WixSharp/SqlString.cs +++ b/Source/src/WixSharp/SqlString.cs @@ -435,7 +435,11 @@ public void Process(ProcessingContext context) XElement sqlString = this.ToXElement(WixExtension.Sql, "SqlString"); component.Add(sqlString); - context.XParent.FindFirst("Component").Parent?.Add(component); + XElement bestParent = context.XParent.FindFirstComponentParent() ?? + context.XParent.FistProgramFilesDir(); + + bestParent.Add(component); + MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context); } else diff --git a/Source/src/WixSharp/User.cs b/Source/src/WixSharp/User.cs index f6870a69..636d37f6 100644 --- a/Source/src/WixSharp/User.cs +++ b/Source/src/WixSharp/User.cs @@ -263,7 +263,7 @@ public void Process(ProcessingContext context) XElement component = this.CreateParentComponent(); component.Add(this.ToXElement(WixExtension.Util, "User")); - XElement bestParent = context.XParent.FindFirst("Component")?.Parent ?? + XElement bestParent = context.XParent.FindFirstComponentParent() ?? context.XParent.FistProgramFilesDir(); bestParent.Add(component);