Skip to content

Add support for formatting file-based apps - #55626

Open
jjonescz wants to merge 3 commits into
mainfrom
dev/jjonescz/49285-sprint-format
Open

Add support for formatting file-based apps#55626
jjonescz wants to merge 3 commits into
mainfrom
dev/jjonescz/49285-sprint-format

Conversation

@jjonescz

@jjonescz jjonescz commented Aug 6, 2026

Copy link
Copy Markdown
Member

Resolves #49285.

(Note that this is currently stacked on top of #55595 because it needs roslyn version from that flow. The CI failures are also unrelated to this PR as they appear in that parent PR too.)

@jjonescz jjonescz added Area-Format Area-run-file Items related to the "dotnet run <file>" effort labels Aug 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jjonescz
jjonescz marked this pull request as ready for review August 6, 2026 11:33
Copilot AI review requested due to automatic review settings August 6, 2026 11:33
@jjonescz
jjonescz requested review from a team as code owners August 6, 2026 11:33
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates dotnet format to accept C# file-based programs (e.g., dotnet format app.cs) by treating eligible .cs entrypoint files as valid “workspace” inputs, updating workspace loading behavior to correctly scope formatting, and adding regression tests and localized help text.

Changes:

  • Extend workspace discovery/help text to allow project/solution or file-based program inputs.
  • Track the loaded ProjectId when opening a single project workspace so referenced projects are excluded reliably.
  • Add unit + CLI scenario tests (and test assets) covering formatted/unformatted file-based apps.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/TestAssets/dotnet-format/for_code_formatter/file_based_app/unformatted.cs New unformatted file-based app input for formatter tests.
test/TestAssets/dotnet-format/for_code_formatter/file_based_app/formatted.cs New formatted baseline for file-based app formatter tests.
test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildCommands.cs Adds CLI-level regression test for dotnet format app.cs.
test/dotnet-format.UnitTests/MSBuild/MSBuildWorkspaceLoaderTests.cs Updates tests for new LoadedWorkspace return type.
test/dotnet-format.UnitTests/CodeFormatterTests.cs Adds file-based app formatting coverage and treats .cs as project workspace in test helper.
test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs Updates for new LoadedWorkspace API.
src/Dotnet.Format/dotnet-format/xlf/Resources.zh-Hant.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.zh-Hans.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.tr.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.ru.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.pt-BR.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.pl.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.ko.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.ja.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.it.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.fr.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.es.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.de.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/xlf/Resources.cs.xlf Localization updates for new/renamed workspace argument strings.
src/Dotnet.Format/dotnet-format/Workspaces/MSBuildWorkspaceLoader.cs Changes loader to return LoadedWorkspace including ProjectId.
src/Dotnet.Format/dotnet-format/Workspaces/MSBuildWorkspaceFinder.cs Accepts file-based program entrypoints as workspace inputs; updates invalid-workspace error.
src/Dotnet.Format/dotnet-format/Resources.resx Updates help/error strings to include file-based apps.
src/Dotnet.Format/dotnet-format/dotnet-format.csproj Adds project reference needed for file-based program support.
src/Dotnet.Format/dotnet-format/Commands/FormatCommandCommon.cs Updates argument name/description to reflect new accepted inputs.
src/Dotnet.Format/dotnet-format/CodeFormatter.cs Uses ProjectId-based scoping when formatting a single project workspace.

Comment thread test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs Outdated
@jjonescz

jjonescz commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
5 pipeline(s) were filtered out due to trigger conditions.

Base automatically changed from darc-main-bf2b710a-36ff-4a1a-8971-c2091395012b to main August 6, 2026 14:38
@mthalman
mthalman requested review from a team as code owners August 6, 2026 14:38
@mthalman
mthalman force-pushed the dev/jjonescz/49285-sprint-format branch from 107f5fe to 0576be4 Compare August 6, 2026 14:38
@jjonescz
jjonescz removed request for a team August 6, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Format Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support file-based apps with dotnet format

3 participants