Support trailing commas and comments in .slnf files#51962
Conversation
|
@copilot please replace the two new net8.0 target frameworks you added with |
|
Tested in codespaces with a slnf that had trailing commas and comments. |
Done in 5fac8cb. Replaced both instances of |
There was a problem hiding this comment.
Pull request overview
This PR adds support for trailing commas and JSON comments in solution filter (.slnf) files, aligning the SDK's behavior with MSBuild's support added in dotnet/msbuild#6346. The change modifies the JSON parsing in SlnFileFactory.CreateFromFilteredSolutionFile to allow these relaxed JSON features, improving developer experience when editing .slnf files.
Key Changes
- Modified
SlnFileFactory.csto passJsonDocumentOptionswithAllowTrailingCommas = trueandCommentHandling = JsonCommentHandling.Skipwhen parsing .slnf files - Added comprehensive test coverage with two new test cases validating both trailing commas and comments work correctly
- Created
TestAppWithTrailingCommaSlnftest asset with two .slnf files demonstrating both features
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/dotnet/SlnFileFactory.cs | Configured JsonDocumentOptions to allow trailing commas and skip comments when parsing .slnf files |
| test/dotnet.Tests/CommandTests/Solution/List/GivenDotnetSlnList.cs | Added two parameterized tests validating both "sln" and "solution" commands work with trailing commas and comments in .slnf files |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/AppWithTrailingComma.slnf | Test asset demonstrating .slnf with trailing comma and comments |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/AppWithComments.slnf | Test asset demonstrating .slnf with multi-line and single-line comments |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/App.sln | Base solution file referenced by the test .slnf files |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/App/App.csproj | App project referenced in the test solution |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/App/Program.cs | Simple console app for test asset |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/Lib/Lib.csproj | Library project referenced in the test solution |
| test/TestAssets/TestProjects/TestAppWithTrailingCommaSlnf/Lib/LibClass.cs | Simple library class for test asset |
5fac8cb to
7c0cb86
Compare
There was a problem hiding this comment.
Should we be using .slnx for new test projects or does .slnf not support .slnx?
There was a problem hiding this comment.
Slnf are supported for slnx - we could make a point of using slnx on new tests if we wanted to. I don't feel super strongly about it because the formats are the same underlying data model. If there were a larger divergence in behavior then I'd be pushing for more slnx test examples.
There was a problem hiding this comment.
I think the benefit for .slnx is "diff-ability". So if you wanted to update the test, using .slnx would make it easier. That's the only reason I suggested it.
There was a problem hiding this comment.
Oh yeah, that's a great point! It's just a better format overall.
7c0cb86 to
690579b
Compare
690579b to
a98e6c3
Compare
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…date copilot instructions Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
a98e6c3 to
600c74b
Compare
|
@copilot can you change the new test to use the new slnx file format and change the two slnf files to target the App.slnx? |
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Done in d551959. Converted App.sln to App.slnx and updated both .slnf files to reference App.slnx. |
net8.0with$(CurrentTargetFramework)in App.csproj and Lib.csprojOriginal prompt
CreateFromFilteredSolutionFileimplementation for trailing comma (and allowing comments) #51929✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.