Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Cli/dotnet/SlnFileFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public static SolutionModel CreateFromFilteredSolutionFile(string filteredSoluti
IEnumerable<string> filteredSolutionProjectPaths;
try
{
JsonElement root = JsonDocument.Parse(File.ReadAllText(filteredSolutionPath)).RootElement;
var options = new JsonDocumentOptions
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
};
JsonElement root = JsonDocument.Parse(File.ReadAllText(filteredSolutionPath), options).RootElement;
originalSolutionPath = Uri.UnescapeDataString(root.GetProperty("solution").GetProperty("path").GetString());
filteredSolutionProjectPaths = [.. root.GetProperty("solution").GetProperty("projects").EnumerateArray().Select(p => p.GetString())];
originalSolutionPathAbsolute = Path.GetFullPath(originalSolutionPath, Path.GetDirectoryName(filteredSolutionPath));
Expand Down
25 changes: 25 additions & 0 deletions test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/App.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{8E5D6DE4-3E3B-4C22-8E3B-4E3B4C228E3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "Lib\Lib.csproj", "{9F6E7EF5-4F4C-5D33-9F4C-5F4C5D339F4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8E5D6DE4-3E3B-4C22-8E3B-4E3B4C228E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E5D6DE4-3E3B-4C22-8E3B-4E3B4C228E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E5D6DE4-3E3B-4C22-8E3B-4E3B4C228E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E5D6DE4-3E3B-4C22-8E3B-4E3B4C228E3B}.Release|Any CPU.Build.0 = Release|Any CPU
{9F6E7EF5-4F4C-5D33-9F4C-5F4C5D339F4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F6E7EF5-4F4C-5D33-9F4C-5F4C5D339F4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F6E7EF5-4F4C-5D33-9F4C-5F4C5D339F4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F6E7EF5-4F4C-5D33-9F4C-5F4C5D339F4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello from App!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
/* Multi-line comment
Testing comment support */
"solution": {
"path": "App.sln",
"projects": [
"App\\App.csproj" // Only include App project
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// This is a solution filter with trailing commas and comments
"solution": {
"path": "App.sln", // Path to the main solution
"projects": [
"App\\App.csproj",
"Lib\\Lib.csproj",
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Lib
{
public class LibClass
{
public string GetMessage()
{
return "Hello from Lib!";
}
}
}
41 changes: 41 additions & 0 deletions test/dotnet.Tests/CommandTests/Solution/List/GivenDotnetSlnList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,46 @@ public void WhenSolutionFilterOriginalPathContainsSpecialCharactersTheyAreUnesca

cmd.Should().Pass();
}

[Theory]
[InlineData("sln")]
[InlineData("solution")]
public void WhenSolutionFilterWithTrailingCommaIsPassedItListsProjects(string solutionCommand)
{
string[] expectedOutput = { $"{CliCommandStrings.ProjectsHeader}",
$"{new string('-', CliCommandStrings.ProjectsHeader.Length)}",
$"{Path.Combine("App", "App.csproj")}",
$"{Path.Combine("Lib", "Lib.csproj")}" };
var projectDirectory = _testAssetsManager
.CopyTestAsset("TestAppWithTrailingCommaSlnf", identifier: "GivenDotnetSlnList-TrailingComma")
.WithSource()
.Path;

var cmd = new DotnetCommand(Log)
.WithWorkingDirectory(projectDirectory)
.Execute(solutionCommand, "AppWithTrailingComma.slnf", "list");
cmd.Should().Pass();
cmd.StdOut.Should().ContainAll(expectedOutput);
}

[Theory]
[InlineData("sln")]
[InlineData("solution")]
public void WhenSolutionFilterWithCommentsIsPassedItListsProjects(string solutionCommand)
{
string[] expectedOutput = { $"{CliCommandStrings.ProjectsHeader}",
$"{new string('-', CliCommandStrings.ProjectsHeader.Length)}",
$"{Path.Combine("App", "App.csproj")}" };
var projectDirectory = _testAssetsManager
.CopyTestAsset("TestAppWithTrailingCommaSlnf", identifier: "GivenDotnetSlnList-Comments")
.WithSource()
.Path;

var cmd = new DotnetCommand(Log)
.WithWorkingDirectory(projectDirectory)
.Execute(solutionCommand, "AppWithComments.slnf", "list");
cmd.Should().Pass();
cmd.StdOut.Should().ContainAll(expectedOutput);
}
}
}