10

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!)

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270

2 Answers2

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>