private static void UpdateBindingRedirectElement(XElement element, AssemblyBinding bindingRedirect) { var bindingRedirectElement = element.Element(AssemblyBinding.GetQualifiedName("bindingRedirect")); // Since we've successfully parsed this node, it has to be valid and this child must exist. Debug.Assert(bindingRedirectElement != null); bindingRedirectElement.Attribute("oldVersion").SetValue(bindingRedirect.OldVersion); bindingRedirectElement.Attribute("newVersion").SetValue(bindingRedirect.NewVersion); }
private static void UpdateBindingRedirectElement( XElement existingDependentAssemblyElement, AssemblyBinding newBindingRedirect) { var existingBindingRedirectElement = existingDependentAssemblyElement.Element(BindingRedirectName); // Since we've successfully parsed this node, it has to be valid and this child must exist. if (existingBindingRedirectElement != null) { existingBindingRedirectElement.SetAttributeValue(XName.Get("oldVersion"), newBindingRedirect.OldVersion); existingBindingRedirectElement.SetAttributeValue(XName.Get("newVersion"), newBindingRedirect.NewVersion); } else { // At this point, <dependentAssemblyElement> already exists, but <bindingRedirectElement> does not. // So, extract the <bindingRedirectElement> from the newDependencyAssemblyElement, and add it // to the existingDependentAssemblyElement var newDependentAssemblyElement = newBindingRedirect.ToXElement(); var newBindingRedirectElement = newDependentAssemblyElement.Element(BindingRedirectName); existingDependentAssemblyElement.AddIndented(newBindingRedirectElement); } }
private static ILookup <AssemblyBinding, XElement> GetAssemblyBindings(XDocument document) { XElement runtime = document.Root.Element("runtime"); IEnumerable <XElement> assemblyBindingElements = Enumerable.Empty <XElement>(); if (runtime != null) { assemblyBindingElements = GetAssemblyBindingElements(runtime); } // We're going to need to know which element is associated with what binding for removal var assemblyElementPairs = from dependentAssemblyElement in assemblyBindingElements select new { Binding = AssemblyBinding.Parse(dependentAssemblyElement), Element = dependentAssemblyElement }; // Return a mapping from binding to element return(assemblyElementPairs.ToLookup(p => p.Binding, p => p.Element)); }