forked from jerriepelser-blog/AnalyzeDotNetProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DependencyGraphService.cs
37 lines (32 loc) · 1.49 KB
/
DependencyGraphService.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
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NuGet.ProjectModel;
namespace AnalyzeDotNetProject
{
/// <remarks>
/// Credit for the stuff happening in here goes to the https://github.com/jaredcnance/dotnet-status project
/// </remarks>
public class DependencyGraphService
{
public DependencyGraphSpec GenerateDependencyGraph(string projectPath)
{
var dotNetRunner = new DotNetRunner();
string dgOutput = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
string[] arguments = new[] {"msbuild", $"\"{projectPath}\"", "/t:GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath={dgOutput}"};
var runStatus = dotNetRunner.Run(Path.GetDirectoryName(projectPath), arguments);
if (runStatus.IsSuccess)
{
//string dependencyGraphText = File.ReadAllText(dgOutput);
//return new DependencyGraphSpec(JsonConvert.DeserializeObject<JObject>(dependencyGraphText));
return DependencyGraphSpec.Load(dgOutput);
}
else
{
throw new Exception($"Unable to process the the project `{projectPath}. Are you sure this is a valid .NET Core or .NET Standard project type?" +
$"\r\n\r\nHere is the full error message returned from the Microsoft Build Engine:\r\n\r\n" + runStatus.Output);
}
}
}
}