Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit b0565e6

Browse files
brthorSridhar-MS
authored andcommitted
fix projectdependnecy finder
1 parent 46ab621 commit b0565e6

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ public IEnumerable<ProjectDependency> ResolveProjectDependencies(ProjectContext
6161

6262
private Dictionary<string, ProjectDependency> FindPossibleProjectDependencies(string projectJsonFilePath)
6363
{
64-
var projectDirectory = Path.GetDirectoryName(projectJsonFilePath);
64+
var projectRootDirectory = GetRootFromProjectJson(projectJsonFilePath);
6565

6666
var projectSearchPaths = new List<string>();
67-
projectSearchPaths.Add(projectDirectory);
68-
projectSearchPaths.Add(Path.GetDirectoryName(projectDirectory));
67+
projectSearchPaths.Add(projectRootDirectory);
6968

70-
var globalPaths = GetGlobalPaths(projectDirectory);
69+
var globalPaths = GetGlobalPaths(projectRootDirectory);
7170
projectSearchPaths = projectSearchPaths.Union(globalPaths).ToList();
7271

7372
var projects = new Dictionary<string, ProjectDependency>(StringComparer.Ordinal);
@@ -105,6 +104,31 @@ private Dictionary<string, ProjectDependency> FindPossibleProjectDependencies(st
105104
return projects;
106105
}
107106

107+
/// <summary>
108+
/// Finds the parent directory of the project.json.
109+
/// </summary>
110+
/// <param name="projectJsonPath">Full path to project.json.</param>
111+
private static string GetRootFromProjectJson(string projectJsonPath)
112+
{
113+
if (!string.IsNullOrEmpty(projectJsonPath))
114+
{
115+
var file = new FileInfo(projectJsonPath);
116+
117+
// If for some reason we are at the root of the drive this will be null
118+
// Use the file directory instead.
119+
if (file.Directory.Parent == null)
120+
{
121+
return file.Directory.FullName;
122+
}
123+
else
124+
{
125+
return file.Directory.Parent.FullName;
126+
}
127+
}
128+
129+
return projectJsonPath;
130+
}
131+
108132
/// <summary>
109133
/// Create the list of potential projects from the search paths.
110134
/// </summary>

0 commit comments

Comments
 (0)