Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the CTRL+E,D or CTRL+E,F key shortcuts but with this extension the command Edit.FormatDocument
is executed on Save.
https://marketplace.visualstudio.com/items?itemName=mynkow.FormatdocumentonSave
There are 5 settings which you could configure:
- Command
- Allowed extensions
- Denied Extensions
- Enable
- Enable in Debug
This is the Visual Studio command which will be invoked when a document is saved. For multiple values you could use space
separated list.
Edit.FormatDocument
Many people were asking how to execute a CodeCleanup on save. It is possible to replace the default command with Analyze.RunDefaultCodeCleanupOnSolution
which executes all the commands configured in the default profile.
note: In rare occasions VisualStudio2019 enters in a infinite loop. A restart or extension reinstall helps. If you know how to reproduce this bug please log an issue.
Specifies all file extensions where the command
is allowed to be executed. For multiple values you could use space
separated list.
allowed_extensions = .*
Specifies all file extensions where the command
is NOT allowed to be executed. For multiple values you could use space
separated list.
denied_extensions =
By default the plugin is disabled in debug mode. You could explicitly configure to have the extension enabled while in a debug session.
enable_in_debug = false
allowed_extensions = .*
denied_extensions = .cs
Result: All documents will be formatted because we explicitly specified that all extensions will be formatted using allowed_extensions = .*
.
allowed_extensions =
denied_extensions = .js
Result: All documents will be formatted except those with .js
extension
allowed_extensions =
denied_extensions = .*
Result: No documents will be formatted
allowed_extensions = .cs
denied_extensions = .*
Result: Only documents with .cs
extension will be formatted
allowed_extensions = .cs
denied_extensions =
Result: All documents will be formatted because nothing is denied
allowed_extensions = .cs
denied_extensions = .cs
Result: All documents will be formatted because there is a conflict
You can configure these settings from the Visual Studio Options menu
Create a .formatconfig
file in the root of your project
Note: If you have a .formatconfig
file, the VS options are ignored!
root = true
[*.*]
enable = true
command = Edit.FormatDocument
allowed_extensions =
denied_extensions = .js .html
root = true
[*.*]
command = Edit.FormatDocument Edit.FormatDocument
allowed_extensions =
denied_extensions = .js .html
If you wish to temporarily disable to extension you could press CapsLock.
By default the extension is disabled while in a debug session. You could change that from the configuration.
You can enable or disable the extension in the configuration, or disable in a .formatconfig
file.
To setup development environment follow the steps:
-
Install
Visual Studio SDK
from Visual Studio Installer https://prnt.sc/umv2ak -
Clone the project
-
Configure debug Open project properties and go to the
Debug
tab. SelectStart external program:
and enter the path to your Visual Studio exe. For exampleC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
. In theCommand line arguments:
type/rootsuffix Exp
https://prnt.sc/umv47r -
Debug When you press
F5
a new instance of Visual Studio will open. From there you need to load an exising solution, file or create a new one. When you pressctrl
+s
it will trigger break points you have set in the initial Visual Studio instance.