I just discovered dotnet-format
, but as far as I understand it's a command line tool that has to be called manually. How can I apply dotnet-format
on saving a file in Visual Studio 2019? (not Visual Studio Code!)
Asked
Active
Viewed 3,390 times
10

stefan.at.kotlin
- 15,347
- 38
- 147
- 270
-
See [Format document on Save](https://marketplace.visualstudio.com/items?itemName=mynkow.FormatdocumentonSave) extension – Alexander Petrov Apr 04 '21 at 12:57
-
@AlexanderPetrov ah thanks, got it that dotnet-format is simply the command line tool for the built-in Visual Studio formatting. Thanks! – stefan.at.kotlin Apr 04 '21 at 13:18
2 Answers
0
Although this is not what the question was about, I have dotnet-format setup to run as a pre-commit hook.
#!/bin/sh
dotnet-format
exit 0
For the on-save formatting and other gimmicks, I use CodeMaid. https://marketplace.visualstudio.com/items?itemName=SteveCadwallader.CodeMaid

Ε Г И І И О
- 11,199
- 1
- 48
- 63
-
My only issue with this approach is that the developer has to install the pre-hook library for this to be triggered. I'm looking for a native solution that works without installing extra tools. Maybe at Build time as a BuildTask, or even using git itself without external dependencies. – Nour May 16 '22 at 20:29
0
You can configure your project to run this command automatically before build. But it will consume build time
<Project>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet format --severity warn --verbosity diagnostic" />
</Target>

Mahmoud-Abdelslam
- 615
- 6
- 15