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.

[v6] dotnet format don't respect --include option

See original GitHub issue

Hi, I’m the maintainer of Husky.Net tool, In big projects using dotnet-format is a real pain, it takes a lot of time to complete. This is one of the reasons that I created Husky.Net. usually, people only want to format changed files( or staged files). In the previous versions (e.g v5) we could’ve easily limited the dotnet-format working area to the specific files using --include but in the last version looks like dotnet-format doing something else in the background and don’t respect that option.

dotnet format --include folder/targetFile.cs folder/targetFile2.cs

The expected behavior is ignoring everything else except the target files. or providing an option to change its behavior. This issue makes dotnet-format v6 almost unusable, how can I fix this problem or change its behavior? Thank you

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:16
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JoeRobichcommented, May 19, 2022

To handle the options not being parsed correctly, we plan to remove the parsing from the CLI side and simply pass through to the dotnet-format tool. I have opened https://github.com/dotnet/sdk/pull/25541 to get this addressed.

As for performance, we have discussed alternate ways to speed up populating our workspace. Ultimately MSBuild will be involved at some point because .NET builds are so highly customizable the only way not to be wrong is to have MSBuild do the work.

  1. We could use a cache of MSBuild .binlog (or other format) containing the code files and dependency information we need. At which point this becomes a staleness problem. If dependencies aren’t being added/removed, then this cache may remain a viable source of information for a long period.
  2. We could develop a Project Server of sorts. This service would have an initial slow startup that you experience today but, while it remains running, future invocations wouldn’t have to pay the MSBuild cost.

We are not committing to either approach today, but know that this a problem that we are thinking on.

1reaction
sander1095commented, May 19, 2022

@JoeRobich Hey Joe! Giving a quick reply here… I guess my example is bad, because when I use --include with actual supported files in my solution, it’s really slow.

So… to improve my example:

dotnet format solution.sln --include src/WebApi/Startup.cs

still results in other non-relevant projects being built/analyzed…

One workaround is simply using dotnet format whitespace which is super quick, but kinda defeats the point of using editorconfig and specific dotnet rules…


Also, what do you mean with the workaround? How is that different than what @alirezanet is posting? The only difference i see is that @alirezanet 's example contain 2 files, where yours only contains one.

I dont think it is a functional workaround to call dotnet format --options here for EACH changed file… this would kill performance even more!

Curious to hear about your reply!

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet format command - .NET CLI
dotnet format is a code formatter that applies style preferences to a project or solution. Preferences will be read from an .editorconfig ...
Read more >
Configure unit tests by using a .runsettings file
NET version on which the tests are run, the directory for the test results ... Select Tools > Options > Test > Auto...
Read more >
How to use dotnet format to format the whole project inside ...
I have a .Net 5 app and want to use dotnet format. First I added commitlint, husky and lint-staged to the repository.
Read more >
Backpacker - Mar 2001 - Page 15 - Google Books Result
This may seem cavalier, but I don't want the trailside risk when there's so ... the risk of insulting a less knowledgeable person,...
Read more >
Popular Science - Dec 2002 - Page 47 - Google Books Result
Vol. 261, No. 6 · ‎ Magazine
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