Beispiel #1
0
        public IDependencyAnalyzerResult Filter(IDependencyAnalyzerResult result)
        {
            var filteredResult = new Dictionary <string, AssemblyReferenceInfo>(result.Assemblies.Count);

            foreach (var reference in result.Assemblies)
            {
                if (reference.Value.ReferencedBy.ToList().Exists(e => e.AssemblyName.Name == "netstandard"))
                {
                    var filteredReference = new AssemblyReferenceInfo(reference.Value.AssemblyName);

                    reference.Value.References
                    .ToList()
                    .ForEach(filteredReference.AddReference);

                    reference.Value.ReferencedBy
                    .Where(referencedBy => referencedBy.AssemblyName.Name != "netstandard")
                    .ToList()
                    .ForEach(filteredReference.AddReferencedBy);
                }
                else
                {
                    filteredResult.Add(reference.Key, reference.Value);
                }
            }

            return(new DependencyAnalyzerResult(result.AnalyzedFiles, filteredResult));
        }
Beispiel #2
0
        private bool HasNotFoundAssembly(IDependencyAnalyzerResult result)
        {
            var dllNotFound = false;

            var orderedAssemblyGroups = result.Assemblies.Values
                                        .GroupBy(ari => ari.AssemblyName.Name)
                                        .OrderBy(g => g.Key);

            foreach (IGrouping <string, AssemblyReferenceInfo> assemblyGroup in orderedAssemblyGroups)
            {
                if (!ShouldAssemblyBeIgnored(assemblyGroup.Key))
                {
                    List <AssemblyReferenceInfo> assemblyInfos =
                        assemblyGroup.OrderBy(x => x.AssemblyName.ToString()).ToList();
                    if (assemblyInfos.Count <= 1)
                    {
                        if (assemblyInfos.Count == 1 && assemblyInfos[0].AssemblySource == AssemblySource.Local)
                        {
                            continue;
                        }

                        if (assemblyInfos.Count <= 0)
                        {
                            continue;
                        }
                    }

                    logger.LogWarning($"Reference \"{assemblyGroup.Key}\" could not be resolved. ");
                    dllNotFound = true;
                }
            }

            return(dllNotFound);
        }
        public IDependencyAnalyzerResult Filter(IDependencyAnalyzerResult result)
        {
            var filteredResult = new Dictionary <string, AssemblyReferenceInfo>(result.Assemblies.Count);

            result.Assemblies
            .Where(r => r.Value.AssemblySource == AssemblySource.NotFound)
            .ToList()
            .ForEach(r => filteredResult.Add(r.Key, r.Value));

            return(new DependencyAnalyzerResult(result.AnalyzedFiles, filteredResult));
        }
Beispiel #4
0
        private IDependencyAnalyzerResult ApplyFilters(IDependencyAnalyzerResult result)
        {
            var filters = new List <IFilter>();

            if (IgnoreNetStandard)
            {
                filters.Add(new NetStandardFilter());
            }
            if (NotFoundOnly)
            {
                filters.Add(new NotFoundOnlyFilter());
            }

            filters.ForEach(f => result = f.Filter(result));
            return(result);
        }
Beispiel #5
0
 public XmlExport(IDependencyAnalyzerResult result, string fileName, ILogger logger)
 {
     _result   = result ?? throw new ArgumentNullException(nameof(result));
     _fileName = fileName?.Trim();
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public ConsoleVisualizer(IDependencyAnalyzerResult result)
 {
     _analyzerResult = result;
 }
        public static XmlDocument Generate(IDependencyAnalyzerResult result, bool skipSystem)
        {
            var document = new XmlDocument();

            document.LoadXml(@"
                  <runtime>
                    <assemblyBinding xmlns=""urn: schemas - microsoft - com:asm.v1"">
                    </assemblyBinding>
                </runtime>");
            var assemblyGroups = result.Assemblies.Values.GroupBy(x => x.AssemblyName);

            foreach (var assemblyGroup in assemblyGroups.OrderBy(i => i.Key.Name))
            {
                if (skipSystem && AssemblyInformationProvider.IsSystemAssembly(assemblyGroup.Key))
                {
                    continue;
                }

                var assemblyInfos = assemblyGroup.OrderBy(x => x.AssemblyName.ToString()).ToList();
                if (assemblyInfos.Count <= 1)
                {
                    if (assemblyInfos.Count == 1 && assemblyInfos[0].AssemblySource == AssemblySource.Local)
                    {
                        continue;
                    }

                    if (assemblyInfos.Count <= 0)
                    {
                        continue;
                    }
                }

                var sortedAssemblies       = assemblyInfos.OrderByDescending(a => a.AssemblyName.Version).ToList();
                var highestAssemblyVersion = sortedAssemblies.Select(a => a.AssemblyName).First().Version;
                var lowestAssemblyVersion  = sortedAssemblies.Select(a => a.AssemblyName).Last().Version;
                var assemblyToUse          = sortedAssemblies.FirstOrDefault(a => a.AssemblySource != AssemblySource.NotFound)?.AssemblyName;
                if (assemblyToUse == null)
                {
                    continue;
                }

                var depedententAssembly = document.CreateElement("dependentAssembly");
                // <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
                // <bindingRedirect oldVersion="0.0.0.0-2.1.2.4000" newVersion="2.1.2.4000" />
                var assemblyIdentity = document.CreateElement("assemblyIdentity");
                assemblyIdentity.SetAttribute("name", assemblyToUse.Name);
                var publicKeyToken = GetPublicKeyTokenFromAssembly(assemblyToUse);
                if (publicKeyToken != null)
                {
                    assemblyIdentity.SetAttribute("publicKeyToken", publicKeyToken);
                }
                var cultureName = assemblyToUse.CultureName;
                assemblyIdentity.SetAttribute("culture", string.IsNullOrEmpty(cultureName) ? "neutral" : cultureName);
                depedententAssembly.AppendChild(assemblyIdentity);
                var bindingRedirect = document.CreateElement("bindingRedirect");
                bindingRedirect.SetAttribute("oldVersion", Invariant($"{lowestAssemblyVersion}-{highestAssemblyVersion}"));
                bindingRedirect.SetAttribute("newVersion", assemblyToUse.Version.ToString());
                depedententAssembly.AppendChild(bindingRedirect);
                document.DocumentElement.FirstChild.AppendChild(depedententAssembly);
            }

            return(document);
        }
 public BindingRedirectExport(IDependencyAnalyzerResult result, string exportFileName, ILogger logger)
 {
     _result         = result;
     _exportFileName = exportFileName;
     _logger         = logger;
 }