-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathProgram.cs
56 lines (46 loc) · 2.33 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Linq;
using NuGet.ProjectModel;
namespace AnalyzeDotNetProject
{
class Program
{
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);
}
}
}
}
}
private static void ReportDependency(LockFileTargetLibrary projectLibrary, LockFileTarget lockFileTargetFramework, int indentLevel)
{
Console.Write(new String(' ', indentLevel * 2));
Console.WriteLine($"{projectLibrary.Name}, v{projectLibrary.Version}");
foreach (var childDependency in projectLibrary.Dependencies)
{
var childLibrary = lockFileTargetFramework.Libraries.FirstOrDefault(library => library.Name == childDependency.Id);
ReportDependency(childLibrary, lockFileTargetFramework, indentLevel + 1);
}
}
}
}