Skip to content

Commit a0507b7

Browse files
committed
Handle projects from upper directories
1 parent c043f68 commit a0507b7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Cli/dotnet/commands/dotnet-sln/add/Program.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ private async Task AddProjectsToSolutionAsync(string solutionFileFullPath, IEnum
100100
foreach (var projectPath in projectPaths)
101101
{
102102
string relativePath = Path.GetRelativePath(Path.GetDirectoryName(solutionFileFullPath), projectPath);
103-
// Add fallback solution folder
104-
string relativeSolutionFolder = Path.GetDirectoryName(relativePath);
105-
// Don't add solution folder if it contains ..
106-
if (relativeSolutionFolder.Contains(".."))
103+
// If the relative path contains "..", it means the project is outside the solution directory.
104+
// In this case, we should not include the ".." in the relative path.
105+
if (relativePath.Contains(".."))
107106
{
108-
relativeSolutionFolder = string.Empty;
107+
relativePath = relativePath.Substring(relativePath.IndexOf(Path.DirectorySeparatorChar));
109108
}
110-
109+
// Add fallback solution folder
110+
string relativeSolutionFolder = Path.GetDirectoryName(relativePath);
111111
if (!_inRoot && solutionFolder is null && !string.IsNullOrEmpty(relativeSolutionFolder))
112112
{
113113
if (relativeSolutionFolder.Split(Path.DirectorySeparatorChar).LastOrDefault() == Path.GetFileNameWithoutExtension(relativePath))

0 commit comments

Comments
 (0)