Skip to content

Commit 4999bbd

Browse files
Copilotbaronfel
andcommitted
Add dotnetcli.host.json for slnf template and normalize path separators
Co-authored-by: baronfel <[email protected]>
1 parent bd55090 commit 4999bbd

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private async Task AddProjectsToSolutionFilterAsync(IEnumerable<string> projectP
248248
// Load the parent solution to validate projects exist in it
249249
SolutionModel parentSolution = SlnFileFactory.CreateFromFileOrDirectory(parentSolutionPath);
250250

251-
// Get existing projects in the filter
251+
// Get existing projects in the filter (already normalized to OS separator by CreateFromFilteredSolutionFile)
252252
var existingProjects = filteredSolution.SolutionProjects.Select(p => p.FilePath).ToHashSet();
253253

254254
// Get solution-relative paths for new projects
@@ -258,6 +258,9 @@ private async Task AddProjectsToSolutionFilterAsync(IEnumerable<string> projectP
258258
{
259259
string parentSolutionRelativePath = Path.GetRelativePath(parentSolutionDirectory, projectPath);
260260

261+
// Normalize to OS separator for consistent comparison
262+
parentSolutionRelativePath = parentSolutionRelativePath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
263+
261264
// Check if project exists in parent solution
262265
var projectInParent = parentSolution.FindProject(parentSolutionRelativePath);
263266
if (projectInParent is null)

src/Cli/dotnet/SlnFileFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public static SolutionModel CreateFromFilteredSolutionFile(string filteredSoluti
9191
{
9292
JsonElement root = JsonDocument.Parse(File.ReadAllText(filteredSolutionPath)).RootElement;
9393
originalSolutionPath = Uri.UnescapeDataString(root.GetProperty("solution").GetProperty("path").GetString());
94+
// Normalize path separators to OS-specific for cross-platform compatibility
95+
originalSolutionPath = originalSolutionPath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
9496
filteredSolutionProjectPaths = [.. root.GetProperty("solution").GetProperty("projects").EnumerateArray().Select(p => p.GetString())];
9597
originalSolutionPathAbsolute = Path.GetFullPath(originalSolutionPath, Path.GetDirectoryName(filteredSolutionPath));
9698
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json.schemastore.org/dotnetcli.host",
3+
"symbolInfo": {
4+
"ParentSolution": {
5+
"longName": "parent-solution",
6+
"shortName": "s"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)