private IEnumerable <AssemblyName> FindReferencesToConsolidate(FileInfo csproj, IGrouping <string, AssemblyName>[] globalReferencesToConsolidate) { var references = _csprojReferenceScanner.ScanForReferencedAssemblies(csproj).ToArray(); foreach (var reference in references) { var match = globalReferencesToConsolidate.Where(g => g.Key == reference.Name).FirstOrDefault(); if (match == null) { Log.Verbose("{AssemblyName} referenced in {Csproj} does not require redirection", reference.Name, csproj.Name); continue; } var highestVersionedAssembltName = match.OrderByDescending(an => an.Version).First(); Log.Debug("Redirecting {AssemblyName} referenced in {Csproj} to {AssemblyVersion}", reference.Name, csproj.Name, highestVersionedAssembltName.Version.ToString()); yield return(highestVersionedAssembltName); } }
public void AddBindingRedirects(DirectoryInfo currentDirectory) { _logger.Verbose("Scanning {CurrentDirectory} and all subdirectories for .csproj files", currentDirectory.FullName); var csprojFiles = _recursingDirectoryScanner .Scan(currentDirectory, f => f.Extension == ".csproj") .ToArray(); var assemblyReferences = csprojFiles .SelectMany(csproj => _csprojReferenceScanner.ScanForReferencedAssemblies(csproj)) .ToArray(); var toConsolidate = _assemblyReferenceConsolidator.DeriveAssembliesToConsolidate(assemblyReferences).ToArray(); foreach (var csproj in csprojFiles) { var bindingRedirector = new SingleProjectBindingRedirector(_csprojReferenceScanner, new BindingRedirectorXmlEditor()); bindingRedirector.Redirect(csproj, toConsolidate); } }