/// <summary>
        /// Processes the ProviderKey bundle attribute.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
        /// <param name="parentElement">Parent element of attribute.</param>
        /// <param name="attribute">The XML attribute for the ProviderKey attribute.</param>
        private void ParseBundleProviderKeyAttribute(SourceLineNumber sourceLineNumbers, XElement parentElement, XAttribute attribute)
        {
            var providerKey = this.Core.GetAttributeValue(sourceLineNumbers, attribute);
            int illegalChar;

            // Make sure the key does not contain any illegal characters or values.
            if (String.IsNullOrEmpty(providerKey))
            {
                this.Messaging.Write(ErrorMessages.IllegalEmptyAttributeValue(sourceLineNumbers, parentElement.Name.LocalName, attribute.Name.LocalName));
            }
            else if (0 <= (illegalChar = providerKey.IndexOfAny(InvalidDependencyCharacters)))
            {
                this.Messaging.Write(CompilerErrors.IllegalCharactersInProvider(sourceLineNumbers, "ProviderKey", providerKey[illegalChar], String.Join(" ", InvalidDependencyCharacters)));
            }
            else if ("ALL" == providerKey)
            {
                this.Messaging.Write(CompilerErrors.ReservedValue(sourceLineNumbers, parentElement.Name.LocalName, "ProviderKey", providerKey));
            }

            if (!this.Messaging.EncounteredError)
            {
                // Generate the primary key for the row.
                var id = this.Core.CreateIdentifier("dep", attribute.Name.LocalName, providerKey);

                // Create the provider symbol for the bundle. The Component_ field is required
                // in the table definition but unused for bundles, so just set it to the valid ID.
                this.Core.AddSymbol(new WixDependencyProviderSymbol(sourceLineNumbers, id)
                {
                    ParentRef   = id.Id,
                    ProviderKey = providerKey,
                    Attributes  = WixDependencyProviderAttributes.ProvidesAttributesBundle,
                });
            }
        }
        /// <summary>
        /// Processes the Provides element.
        /// </summary>
        /// <param name="node">The XML node for the Provides element.</param>
        /// <param name="packageType">The type of the package being chained into a bundle, or null if building an MSI package.</param>
        /// <param name="parentId">The identifier of the parent component or package.</param>
        /// <param name="possibleKeyPath">Possible KeyPath identifier.</param>
        /// <returns>Yes if this is the keypath.</returns>
        private YesNoType ParseProvidesElement(XElement node, WixBundlePackageType?packageType, string parentId, out string possibleKeyPath)
        {
            possibleKeyPath = null;

            var        sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            Identifier id          = null;
            string     key         = null;
            string     version     = null;
            string     displayName = null;

            foreach (var attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Id":
                        id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib);
                        break;

                    case "Key":
                        key = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    case "Version":
                        version = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib);
                        break;

                    case "DisplayName":
                        displayName = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.Core.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionAttribute(node, attrib);
                }
            }

            // Make sure the key is valid. The key will default to the ProductCode for MSI packages
            // and the package code for MSP packages in the binder if not specified.
            if (!String.IsNullOrEmpty(key))
            {
                int illegalChar;

                // Make sure the key does not contain any illegal characters or values.
                if (0 <= (illegalChar = key.IndexOfAny(InvalidDependencyCharacters)))
                {
                    this.Messaging.Write(CompilerErrors.IllegalCharactersInProvider(sourceLineNumbers, "Key", key[illegalChar], String.Join(" ", InvalidDependencyCharacters)));
                }
                else if ("ALL" == key)
                {
                    this.Messaging.Write(CompilerErrors.ReservedValue(sourceLineNumbers, node.Name.LocalName, "Key", key));
                }
            }
            else if (!packageType.HasValue)
            {
                // Make sure the ProductCode is authored and set the key.
                this.Core.CreateSimpleReference(sourceLineNumbers, SymbolDefinitions.Property, "ProductCode");
                key = "!(bind.property.ProductCode)";
            }
            else if (WixBundlePackageType.Exe == packageType || WixBundlePackageType.Msu == packageType)
            {
                // Must specify the provider key when authored for a package.
                this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Key"));
            }

            // The Version attribute should not be authored in or for an MSI package.
            if (!String.IsNullOrEmpty(version))
            {
                switch (packageType)
                {
                case null:
                    this.Messaging.Write(CompilerWarnings.DiscouragedVersionAttribute(sourceLineNumbers));
                    break;

                case WixBundlePackageType.Msi:
                    this.Messaging.Write(CompilerWarnings.DiscouragedVersionAttribute(sourceLineNumbers, parentId));
                    break;
                }
            }
            else if (WixBundlePackageType.Msp == packageType || WixBundlePackageType.Msu == packageType)
            {
                // Must specify the Version when authored for packages that do not contain a version.
                this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Version"));
            }

            // Need the element ID for child element processing, so generate now if not authored.
            if (null == id)
            {
                id = this.Core.CreateIdentifier("dep", node.Name.LocalName, parentId, key);
            }

            foreach (var child in node.Elements())
            {
                if (CompilerCore.WixNamespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "Requires":
                        this.ParseRequiresElement(child, id.Id);
                        break;

                    case "RequiresRef":
                        this.ParseRequiresRefElement(child, id.Id, requiresAction: !packageType.HasValue);
                        break;

                    default:
                        this.Core.UnexpectedElement(node, child);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionElement(node, child);
                }
            }

            if (!this.Messaging.EncounteredError)
            {
                var symbol = this.Core.AddSymbol(new WixDependencyProviderSymbol(sourceLineNumbers, id)
                {
                    ParentRef   = parentId,
                    ProviderKey = key,
                });

                if (!String.IsNullOrEmpty(version))
                {
                    symbol.Version = version;
                }

                if (!String.IsNullOrEmpty(displayName))
                {
                    symbol.DisplayName = displayName;
                }

                if (!packageType.HasValue)
                {
                    // Generate registry rows for the provider using binder properties.
                    var keyProvides = String.Concat(DependencyRegistryRoot, key);
                    var root        = RegistryRootType.MachineUser;

                    var value = "[ProductCode]";
                    this.Core.CreateRegistryRow(sourceLineNumbers, root, keyProvides, null, value, parentId);

                    value = !String.IsNullOrEmpty(version) ? version : "[ProductVersion]";
                    var versionRegistrySymbol = this.Core.CreateRegistryRow(sourceLineNumbers, root, keyProvides, "Version", value, parentId);

                    value = !String.IsNullOrEmpty(displayName) ? displayName : "[ProductName]";
                    this.Core.CreateRegistryRow(sourceLineNumbers, root, keyProvides, "DisplayName", value, parentId);

                    // Use the Version registry value and use that as a potential key path.
                    possibleKeyPath = versionRegistrySymbol.Id;
                }
            }

            return(YesNoType.NotSet);
        }