Skip to content

Instantly share code, notes, and snippets.

@danuw
Created October 13, 2022 18:38
Show Gist options
  • Save danuw/fddc7dcc0a0963f876dc471961060127 to your computer and use it in GitHub Desktop.
Save danuw/fddc7dcc0a0963f876dc471961060127 to your computer and use it in GitHub Desktop.
List project dependencies (not recursive yet)
using System.Xml;
// Set up a set of projects using https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference
var projectPath = "../Project1/Project1.csproj";
Console.WriteLine($"List of Project dependencies for {projectPath}");
var listOfProjectsChecked = new List<string>();
var listOfDependencies = new List<string>();
XmlDocument doc = new XmlDocument();
doc.Load(projectPath);
XmlNodeList elemList = doc.GetElementsByTagName("ProjectReference");
Console.WriteLine($"There are '{elemList.Count}' dependencies:");
for (int i = 0; i < elemList.Count; i++)
{
string attrVal = elemList[i].Attributes["Include"].Value;
listOfProjectsChecked.Add(attrVal);
}
listOfProjectsChecked.Distinct().ToList().ForEach(i => Console.WriteLine(i));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment