question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet-format: accept a list of files to format (instead of a full workspace)

See original GitHub issue

Version Used: dotnet-format 3.0.0-beta4-19105-10 (70a2f514eb3932648f771b086834cb0a376fee20)

Steps to Reproduce:

  1. Change a number of files (so they appear in VCS output, such as git diff --name-only)
  2. Pass that file list as command line parameters into dotnet format (or try to pipe them into stdin)

Expected Behavior: dotnet format only changes the passed files instead of the whole project (or solution)

Actual Behavior: dotnet format errors out with either “Both a MSBuild project file and solution file found in $path. Specify which one to use with the --workspace option” or “Unrecognized command or argument ‘path/to/file.cs’”. Or somewhat…not sure if I should call it worse or just different: it runs successfully, formatting all files referenced by the project or solution (in case only a single project or solution file is found in the current working directory).

Intended Use-Case: We run a few things as part of our CI (such as static analysis), and we’d also like to use dotnet format as a way to enforce code style before it even reaches the first review by a human. Right now this isn’t too feasible as dotnet format takes quite a while on larger solutions with a lot of files; and running it only on the changed files would significantly improve the time to feedback (with the intention to simply error out in case it produces any changes in the CI working copy).

For smaller change sets, passing file names as command line parameter is likely a usable solution, but the larger the change set the more likely it would be to reach a length limit for arguments; so piping it into stdin would probably be the better approach there.

Or, alternatively (if it makes sense to do so), support this use case from within dotnet format itself (or a tool derived from it), along with the --dry-run switch: stop processing as soon as a change would have been made and return an error code that can be checked by a caller.

Thoughts and ideas are more than welcome, especially in case I missed some other tooling that already does this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JoeRobichcommented, Mar 24, 2019

This is available on myget version 3.0.4-prerelease.19171.3 and later

dotnet tool install -g dotnet-format --version 3.0.4-prerelease.19171.3 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
1reaction
jmarolfcommented, Feb 21, 2019

@BhaaLseN you did the right thing. I just put this repo together recently

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet format command - .NET CLI
A space-separated list of relative file or folder paths to include in formatting. The default is all files in the solution or project....
Read more >
How to use dotnet format to format the whole project inside ...
What is the correct command to simply lint the whole C# project? Update. I tried to change this line in the package.json from....
Read more >
EditorConfig code formatting from the command line with . ...
Formatting code files in project 'hanselminutes.core.tests'. Format complete. You can see in the screenshot below where dotnet format used its ...
Read more >
Dotnet Format and File Scoped Namespaces | Blog
The dotnet format tool is a great way to quickly apply formatting from your .editorconfig to your entire project or solution. It handles...
Read more >
User and Workspace Settings
The Settings editor is the UI that lets you review and modify setting values that are stored in a settings.json file. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found