Skip to content

Commit 0826cbe

Browse files
authored
sln-add: Don't add solution folders outside the scope of solution directory (#48611)
1 parent 6b8e90c commit 0826cbe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ 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 if relative path does not contain `..`.
104-
string relativeSolutionFolder = relativePath.Split(Path.DirectorySeparatorChar).Any(p => p == "..")
103+
// Add auto-generated solution folder if relative path exists in the solution directory
104+
string relativeSolutionFolder = (relativePath.Split(Path.DirectorySeparatorChar).Any(p => p == "..") || Path.IsPathRooted(relativePath))
105105
? string.Empty : Path.GetDirectoryName(relativePath);
106106

107107
if (!_inRoot && solutionFolder is null && !string.IsNullOrEmpty(relativeSolutionFolder))

0 commit comments

Comments
 (0)