From b0565e649811c119af62c9bb661348b75b0a68b7 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Fri, 23 Sep 2016 11:47:56 -0700 Subject: [PATCH] fix projectdependnecy finder --- .../ProjectDependencyFinder.cs | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index 0fc678c1f..30473cece 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -61,13 +61,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration private Dictionary FindPossibleProjectDependencies(string projectJsonFilePath) { - var projectDirectory = Path.GetDirectoryName(projectJsonFilePath); + var projectRootDirectory = GetRootFromProjectJson(projectJsonFilePath); var projectSearchPaths = new List(); - projectSearchPaths.Add(projectDirectory); - projectSearchPaths.Add(Path.GetDirectoryName(projectDirectory)); + projectSearchPaths.Add(projectRootDirectory); - var globalPaths = GetGlobalPaths(projectDirectory); + var globalPaths = GetGlobalPaths(projectRootDirectory); projectSearchPaths = projectSearchPaths.Union(globalPaths).ToList(); var projects = new Dictionary(StringComparer.Ordinal); @@ -105,6 +104,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration return projects; } + /// + /// Finds the parent directory of the project.json. + /// + /// Full path to project.json. + private static string GetRootFromProjectJson(string projectJsonPath) + { + if (!string.IsNullOrEmpty(projectJsonPath)) + { + var file = new FileInfo(projectJsonPath); + + // If for some reason we are at the root of the drive this will be null + // Use the file directory instead. + if (file.Directory.Parent == null) + { + return file.Directory.FullName; + } + else + { + return file.Directory.Parent.FullName; + } + } + + return projectJsonPath; + } + /// /// Create the list of potential projects from the search paths. ///