From f8ee97926a8d7c35842d6e1a3604753295471284 Mon Sep 17 00:00:00 2001 From: Oleg Shilo Date: Sat, 5 Oct 2024 20:15:23 +1000 Subject: [PATCH] wix4: #1652: Bundle DotNetCompatibilityCheck element suport --- .../Bootstrapper/DotNetCompatibilityCheck.cs | 148 ++++++++++++++++++ Source/src/WixSharp/WixSharp.csproj | 1 + 2 files changed, 149 insertions(+) create mode 100644 Source/src/WixSharp/Bootstrapper/DotNetCompatibilityCheck.cs diff --git a/Source/src/WixSharp/Bootstrapper/DotNetCompatibilityCheck.cs b/Source/src/WixSharp/Bootstrapper/DotNetCompatibilityCheck.cs new file mode 100644 index 00000000..2c5fe6cd --- /dev/null +++ b/Source/src/WixSharp/Bootstrapper/DotNetCompatibilityCheck.cs @@ -0,0 +1,148 @@ +using System; +using System.Xml.Linq; + +namespace WixSharp.Bootstrapper +{ + /// + /// Represents a class for checking .NET compatibility. + /// The following is an example adding DotNetCompatibilityCheck as an XML element.> + /// + /// bundle.AddXml(new DotNetCompatibilityCheck( + /// "DOTNET_RUNTIME_CHECK", + /// RollForward.latestMinor, + /// RuntimeType.desktop, + /// Platform.x64, + /// new Version(8, 0, 0, 0))); + /// + /// + /// + /// The following is an example adding DotNetCompatibilityCheck as an entity.> + /// + /// bundle.GenericItems.Add(new DotNetCompatibilityCheck( + /// "DOTNET_RUNTIME_CHECK", + /// RollForward.latestMinor, + /// RuntimeType.desktop, + /// Platform.x64, + /// new Version(8, 0, 0, 0))); + /// + /// + /// + public class DotNetCompatibilityCheck : WixEntity, IXmlAware, IGenericEntity + { + /// + /// Gets or sets the Id value of the . + /// This value is used as a Id for the corresponding WiX XML element.If the value is not specified explicitly by the user the Wix# compiler + /// generates it automatically insuring its uniqueness. + /// Note: The ID auto-generation is triggered on the first access (evaluation) and in order to make the id + /// allocation deterministic the compiler resets ID generator just before the build starts. However if you + /// accessing any auto-id before the Build*() is called you can it interferes with the ID auto generation and eventually + /// lead to the WiX ID duplications. To prevent this from happening either: + /// - Avoid evaluating the auto-generated IDs values before the call to Build*() - Set the IDs (to be evaluated) explicitly - Prevent resetting auto-ID generator by setting WixEntity.DoNotResetIdGenerator to true"; + /// + /// + /// The id. + /// + [Xml] + public new string Id { get => base.Id; set => base.Id = value; } + + /// + /// Gets the name of the property to set. + /// + [Xml] + public string Property; + + /// + /// Gets the roll forward policy for the compatibility check. + /// + [Xml] + public RollForward RollForward; + + /// + /// Gets the runtime type for the compatibility check. + /// + [Xml] + public RuntimeType RuntimeType; + + /// + /// Gets the platform for the compatibility check. + /// + [Xml] + public Platform Platform; + + /// + /// Gets the version for the compatibility check. + /// + [Xml] + public Version Version; + + /// + /// Initializes a new instance of the class. + /// + public DotNetCompatibilityCheck() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The identifier of the compatibility check. + /// The name of the property to set. + /// The roll forward policy. + /// The runtime type. + /// The platform. + /// The version. + public DotNetCompatibilityCheck(string id, string property, RollForward rollForward, RuntimeType runtime, Platform platform, Version version) + { + Id = id; + Property = property; + RollForward = rollForward; + RuntimeType = runtime; + Platform = platform; + Version = version; + } + + /// + /// Initializes a new instance of the class. + /// + /// The identifier of the compatibility check. + /// The name of the property to set. + /// The roll forward policy. + /// The runtime type. + /// The platform. + /// The version. + public DotNetCompatibilityCheck(string property, RollForward rollForward, RuntimeType runtime, Platform platform, Version version) + { + Property = property; + RollForward = rollForward; + RuntimeType = runtime; + Platform = platform; + Version = version; + } + + /// + /// Emits WiX XML. + /// + /// + public XElement ToXml() + => new XElement("Fragment", this.ToXElement(WixExtension.NetFx.ToXName("DotNetCompatibilityCheck"))); + + /// + /// Adds itself as an XML content into the WiX source being generated from the . See 'Wix#/samples/Extensions' sample for the details on how + /// to implement this interface correctly. + /// + /// The context. + public void Process(ProcessingContext context) + { + // context.XParent is not inserted in the XML doc yet so its parent (XML root) is not available. + // Thus the line below will not work: + // context.XParent.Parent.Add(new XElement("Fragment", this.ToXml())); + + // Thus instead of injecting the element in the XParent directly schedule the injection event when the doc + // is generated + + context.Project.Include(WixExtension.NetFx); + context.Project.WixSourceGenerated += (doc) => + doc.Root.Add(this.ToXml()); + } + } +} \ No newline at end of file diff --git a/Source/src/WixSharp/WixSharp.csproj b/Source/src/WixSharp/WixSharp.csproj index 05501be6..ec31376f 100644 --- a/Source/src/WixSharp/WixSharp.csproj +++ b/Source/src/WixSharp/WixSharp.csproj @@ -111,6 +111,7 @@ +