diff --git a/MsBuildProjectReferenceDependencyGraph/MSBuildUtilities.cs b/MsBuildProjectReferenceDependencyGraph/MSBuildUtilities.cs index 6811ee8..1bfef65 100644 --- a/MsBuildProjectReferenceDependencyGraph/MSBuildUtilities.cs +++ b/MsBuildProjectReferenceDependencyGraph/MSBuildUtilities.cs @@ -6,6 +6,7 @@ namespace MsBuildProjectReferenceDependencyGraph { + using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -139,16 +140,33 @@ public static IEnumerable PackageReferences(string targetProject) /// An IEnumerable that contains all the fully qualified ProjectReference paths. public static IEnumerable 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 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", " "); } }