public void ParseAssemblyBindingConfigSectionPreservesContent() { // Arrange string assemblyBindingXml = @"<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1""> <dependentAssembly> <assemblyIdentity name=""myAssembly"" publicKeyToken=""32ab4ba45e0a69a1"" culture=""neutral"" processorArchitecture=""x86"" /> <bindingRedirect oldVersion=""0.0.0.1-1.0.0.0"" newVersion=""2.0.0.0""/> <codeBase version=""2.0.0.0"" href=""http://www.litwareinc.com/myAssembly.dll""/> <publisherPolicy apply=""no""/> </dependentAssembly> </assemblyBinding>"; var dependentAssembly = XElement.Parse(assemblyBindingXml).Elements().First(); // Act var binding = AssemblyBinding.Parse(dependentAssembly); // Assert Assert.Equal("myAssembly", binding.Name); Assert.Equal("32ab4ba45e0a69a1", binding.PublicKeyToken); Assert.Equal("neutral", binding.Culture); Assert.Equal("x86", binding.ProcessorArchitecture); Assert.Equal("0.0.0.1-1.0.0.0", binding.OldVersion); Assert.Equal("2.0.0.0", binding.NewVersion); Assert.Equal("2.0.0.0", binding.CodeBaseVersion); Assert.Equal("http://www.litwareinc.com/myAssembly.dll", binding.CodeBaseHref); Assert.Equal("no", binding.PublisherPolicy); Assert.Equal(@"<dependentAssembly xmlns=""urn:schemas-microsoft-com:asm.v1""> <assemblyIdentity name=""myAssembly"" publicKeyToken=""32ab4ba45e0a69a1"" culture=""neutral"" processorArchitecture=""x86"" /> <bindingRedirect oldVersion=""0.0.0.1-1.0.0.0"" newVersion=""2.0.0.0"" /> <publisherPolicy apply=""no"" /> <codeBase href=""http://www.litwareinc.com/myAssembly.dll"" version=""2.0.0.0"" /> </dependentAssembly>", binding.ToString()); }
private void RemoveBindingRedirects() { IEnumerable <AssemblyBinding> bindingRedirects = BindingRedirectResolver.GetBindingRedirects(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain); string configurationFilePath = Path.Combine(mProjectManager.Project.Root, mConfigurationFileName); XDocument document = XDocument.Load(configurationFilePath); XElement runtimeElement = document.Root.Element("runtime"); IEnumerable <XElement> assemblyBindingElements = Enumerable.Empty <XElement>(); if (runtimeElement != null) { assemblyBindingElements = runtimeElement.Elements(XName.Get("assemblyBinding", "urn:schemas-microsoft-com:asm.v1")).Elements(XName.Get("dependentAssembly", "urn:schemas-microsoft-com:asm.v1")); } IEnumerable <AssemblyBinding> configurationBindingRedirects = assemblyBindingElements.Select(x => AssemblyBinding.Parse(x)); IEnumerable <AssemblyBinding> candidates = configurationBindingRedirects.Except(bindingRedirects); if (candidates.Any()) { BindingRedirectManager bindingRedirectManager = new BindingRedirectManager(mProjectManager.Project, mConfigurationFileName); bindingRedirectManager.RemoveBindingRedirects(candidates); } }