/// <summary> /// This method is used to initialize the plug-in at the start of the build process /// </summary> /// <param name="buildProcess">A reference to the current build process</param> /// <param name="configuration">The configuration data that the plug-in should use to initialize itself</param> public void Initialize(BuildProcess buildProcess, XElement configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } builder = buildProcess ?? throw new ArgumentNullException(nameof(buildProcess)); redirects = new List <BindingRedirectSettings>(); ignoreIfUnresolved = new List <string>(); var metadata = (HelpFileBuilderPlugInExportAttribute)this.GetType().GetCustomAttributes( typeof(HelpFileBuilderPlugInExportAttribute), false).First(); builder.ReportProgress("{0} Version {1}\r\n{2}", metadata.Id, metadata.Version, metadata.Copyright); // Transform the configuration elements to handle substitution tags string config = buildProcess.SubstitutionTags.TransformText(configuration.ToString()); var settings = XElement.Parse(config); if (settings.IsEmpty) { throw new BuilderException("ABR0001", "The Assembly Binding Redirection Resolver plug-in " + "has not been configured yet"); } // Load the configuration useGac = (bool)settings.Attribute("useGAC"); foreach (var r in settings.Element("assemblyBinding").Descendants("dependentAssembly")) { redirects.Add(BindingRedirectSettings.FromXml(builder.CurrentProject, r)); } foreach (var i in settings.Element("ignoreIfUnresolved").Descendants("assemblyIdentity")) { ignoreIfUnresolved.Add(i.Attribute("name").Value); } }
//===================================================================== /// <summary> /// Create a binding redirect settings instance from an XPath navigator containing the settings /// </summary> /// <param name="pathProvider">The base path provider object</param> /// <param name="navigator">The XPath navigator from which to obtain the settings</param> /// <returns>A <see cref="BindingRedirectSettings"/> object containing the settings from the XPath /// navigator.</returns> /// <remarks>It should contain an element called <c>dependentAssembly</c> with a <c>configFile</c> /// attribute or a nested <c>assemblyIdentity</c> and <c>bindingRedirect</c> element that define /// the settings.</remarks> public static BindingRedirectSettings FromXPathNavigator(IBasePathProvider pathProvider, XPathNavigator navigator) { BindingRedirectSettings brs = new BindingRedirectSettings(pathProvider); XPathNavigator nav; string value; string[] versions; Version tempVersion; if(navigator != null) { value = navigator.GetAttribute("importFrom", String.Empty).Trim(); if(value.Length != 0) brs.ConfigurationFile = new FilePath(value, pathProvider); else { nav = navigator.SelectSingleNode("assemblyIdentity"); if(nav != null) { brs.AssemblyName = nav.GetAttribute("name", String.Empty).Trim(); brs.PublicKeyToken = nav.GetAttribute("publicKeyToken", String.Empty).Trim(); brs.Culture = nav.GetAttribute("culture", String.Empty).Trim(); } nav = navigator.SelectSingleNode("bindingRedirect"); if(nav != null) { value = nav.GetAttribute("newVersion", String.Empty).Trim(); if(value.Length != 0) brs.NewVersion = new Version(value); value = nav.GetAttribute("oldVersion", String.Empty).Trim(); versions = value.Split('-'); if(versions.Length == 2) { if(versions[0].Trim().Length != 0) brs.OldVersion = new Version(versions[0]); if(versions[1].Trim().Length != 0) brs.OldVersionTo = new Version(versions[1]); if(brs.OldVersion > brs.oldVersionTo) { tempVersion = brs.OldVersion; brs.OldVersion = brs.oldVersionTo; brs.oldVersionTo = tempVersion; } } else brs.OldVersion = new Version(versions[0]); } } } return brs; }
//===================================================================== /// <summary> /// Create a binding redirect settings instance from an XPath navigator containing the settings /// </summary> /// <param name="pathProvider">The base path provider object</param> /// <param name="navigator">The XPath navigator from which to obtain the settings</param> /// <returns>A <see cref="BindingRedirectSettings"/> object containing the settings from the XPath /// navigator.</returns> /// <remarks>It should contain an element called <c>dependentAssembly</c> with a <c>configFile</c> /// attribute or a nested <c>assemblyIdentity</c> and <c>bindingRedirect</c> element that define /// the settings.</remarks> public static BindingRedirectSettings FromXPathNavigator(IBasePathProvider pathProvider, XPathNavigator navigator) { BindingRedirectSettings brs = new BindingRedirectSettings(pathProvider); XPathNavigator nav; string value; string[] versions; Version tempVersion; if (navigator != null) { value = navigator.GetAttribute("importFrom", String.Empty).Trim(); if (value.Length != 0) { brs.ConfigurationFile = new FilePath(value, pathProvider); } else { nav = navigator.SelectSingleNode("assemblyIdentity"); if (nav != null) { brs.AssemblyName = nav.GetAttribute("name", String.Empty).Trim(); brs.PublicKeyToken = nav.GetAttribute("publicKeyToken", String.Empty).Trim(); brs.Culture = nav.GetAttribute("culture", String.Empty).Trim(); } nav = navigator.SelectSingleNode("bindingRedirect"); if (nav != null) { value = nav.GetAttribute("newVersion", String.Empty).Trim(); if (value.Length != 0) { brs.NewVersion = new Version(value); } value = nav.GetAttribute("oldVersion", String.Empty).Trim(); versions = value.Split('-'); if (versions.Length == 2) { if (versions[0].Trim().Length != 0) { brs.OldVersion = new Version(versions[0]); } if (versions[1].Trim().Length != 0) { brs.OldVersionTo = new Version(versions[1]); } if (brs.OldVersion > brs.oldVersionTo) { tempVersion = brs.OldVersion; brs.OldVersion = brs.oldVersionTo; brs.oldVersionTo = tempVersion; } } else { brs.OldVersion = new Version(versions[0]); } } } } return(brs); }