Пример #1
0
        private IEnumerable <UnusedPackage> GetUnusedPackages(FrameworkName targetFramework, bool lookAtUnusedUsings)
        {
            var usedAssemblyPaths = RoslynProject.Documents
                                    .SelectMany(d => d.GetUsedAssemblies(lookAtUnusedUsings))
                                    .Select(a => a.Identity.Location)
                                    .Where(p => !string.IsNullOrEmpty(p))
                                    .Distinct().ToList();

            return(Packages
                   // Packages not referenced by other packages ...
                   .GetDirectPackages(targetFramework)
                   // ... that have assemblies ...
                   .Where(p => p.AssemblyReferences.Any())
                   // ... and the namespaces in those assemblies do not exist in the project ...
                   .Where(p => p.GetTypes().Select(t => t.FullName).Intersect(MsBuildProject.GetNamespaces()).IsEmpty())
                   // ... and the assemblies are not used by symbols in the project
                   .Where(p => !p.GetAssemblyPaths().Any(a => usedAssemblyPaths.Any(u => u.Contains(a))))
                   .Where(p => !p.Id.Equals("Aspose.Words")) // Roslyn seems to have a problem with this package
                   .Select(p => new UnusedPackage(p)));
        }