Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions MsBuildProjectReferenceDependencyGraph/MSBuildUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MsBuildProjectReferenceDependencyGraph
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -139,16 +140,33 @@ public static IEnumerable<string> PackageReferences(string targetProject)
/// <returns>An IEnumerable that contains all the fully qualified ProjectReference paths.</returns>
public static IEnumerable<string> ProjectDependencies(string targetProject)
{
XDocument projXml = XDocument.Load(targetProject);
XDocument projXml = null;
try
{
projXml = XDocument.Load(targetProject);
}
catch (DirectoryNotFoundException)
{
Console.Error.WriteLine($@"ERROR: Could not load directory for {targetProject}");
}
catch (FileNotFoundException)
{
Console.Error.WriteLine($@"ERROR: Could not load file for {targetProject}");
}

if (projXml == null) yield break;

IEnumerable<XElement> projectReferences = projXml.Descendants(msbuildNS + "ProjectReference");

foreach (XElement projectReference in projectReferences)
{
string relativeProjectPath = projectReference.Attribute("Include").Value;
string resolvedPath = Path.GetFullPath(relativeProjectPath, Path.GetDirectoryName(targetProject));
string resolvedPath = Path.GetFullPath(UrlDecodePaths(relativeProjectPath),
Path.GetDirectoryName(targetProject));
yield return resolvedPath;
}
}

private static string UrlDecodePaths(string path) => path.Replace("%20", " ");
}
}