static void Main(string[] args)
        {
            // Replace to point to your project or solution
            string projectPath = @"c:\development\jerriep\dotnet-outdated\DotNetOutdated.sln";

            var dependencyGraphService = new DependencyGraphService();
            var dependencyGraph        = dependencyGraphService.GenerateDependencyGraph(projectPath);

            foreach (var project in dependencyGraph.Projects.Where(p => p.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference))
            {
                // Generate lock file
                var lockFileService = new LockFileService();
                var lockFile        = lockFileService.GetLockFile(project.FilePath, project.RestoreMetadata.OutputPath);

                Console.WriteLine(project.Name);

                foreach (var targetFramework in project.TargetFrameworks)
                {
                    Console.WriteLine($"  [{targetFramework.FrameworkName}]");

                    var lockFileTargetFramework = lockFile.Targets.FirstOrDefault(t => t.TargetFramework.Equals(targetFramework.FrameworkName));
                    if (lockFileTargetFramework != null)
                    {
                        foreach (var dependency in targetFramework.Dependencies)
                        {
                            var projectLibrary = lockFileTargetFramework.Libraries.FirstOrDefault(library => library.Name == dependency.Name);

                            ReportDependency(projectLibrary, lockFileTargetFramework, 1);
                        }
                    }
                }
            }
        }
示例#2
0
        private static void RunFromOptions(Options options)
        {
            var dependencyGraphService = new DependencyGraphService();
            var dependencyGraph        = dependencyGraphService.GenerateDependencyGraph(options.ProjectPath);

            foreach (var project in dependencyGraph.Projects.Where(p => p.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference))
            {
                // Generate lock file
                var lockFileService = new LockFileService();
                var lockFile        = lockFileService.GetLockFile(project.FilePath, project.RestoreMetadata.OutputPath);

                foreach (var targetFramework in project.TargetFrameworks)
                {
                    Console.WriteLine($"{project.Name}  [{targetFramework.FrameworkName}]");

                    var lockFileTargetFramework = lockFile.Targets.FirstOrDefault(t => t.TargetFramework.Equals(targetFramework.FrameworkName));
                    if (lockFileTargetFramework != null)
                    {
                        foreach (var dependency in targetFramework.Dependencies)
                        {
                            var projectLibrary = lockFileTargetFramework.Libraries.FirstOrDefault(library => library.Name == dependency.Name);

                            ReportDependency(projectLibrary, lockFileTargetFramework, 1);
                        }
                    }
                }
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            // Replace to point to your project or solution
            string projectPath = @"C:\LB\VEKM\Lb.Vekm.Event.Database\src\Lb.VEKM.Event.Database.sln";

            var dependencyGraphService = new DependencyGraphService();
            var dependencyGraph = dependencyGraphService.GenerateDependencyGraph(projectPath);

            foreach (var project in dependencyGraph.Projects.Where(p => p.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference))
            {
                // Generate lock file
                var lockFileService = new LockFileService();
                var lockFile = lockFileService.GetLockFile(project.FilePath, project.RestoreMetadata.OutputPath);

                stringBuilder.AppendLine(project.Name);

                foreach (var targetFramework in project.TargetFrameworks)
                {
                    var dependencies = new List<Dependency>();

                    stringBuilder.AppendLine($"  [{targetFramework.FrameworkName}]");

                    var lockFileTargetFramework = lockFile.Targets.FirstOrDefault(t => t.TargetFramework.Equals(targetFramework.FrameworkName));
                    if (lockFileTargetFramework != null)
                    {
                        foreach (var dependency in targetFramework.Dependencies)
                        {
                            var projectLibrary = lockFileTargetFramework.Libraries.FirstOrDefault(library => library.Name == dependency.Name);
                            var reportDependency = ReportDependency(projectLibrary, lockFileTargetFramework, 1);

                            if (reportDependency == null) continue;

                            dependencies.Add(reportDependency);
                        }
                    }

                    var childrenDependencies = dependencies.SelectMany(dep => dep.Children).ToList();
                    var removableDependencies = new List<Dependency>();

                    foreach (var dependency in dependencies)
                    {
                        var children = childrenDependencies.Where(c => c.Equals(dependency)).ToList();

                        if (children.Count > 0)
                        {
                            dependency.ContainingPackages = children;
                            removableDependencies.Add(dependency);
                        }
                    }

                    var removableContent = string.Join(Environment.NewLine + new string(' ', 3), removableDependencies.Select(dep => dep.ToString()));

                    if (removableContent.Length > 0)
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine("Removable Dependencies");
                        stringBuilder.Append(new string(' ', 3) + removableContent);
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine();
                    }
                }
            }

            Console.WriteLine(stringBuilder.ToString());
            Console.Read();
        }