Skip to content
| Marketplace
Sign in
Visual Studio>Tools>FormatC#WhenOpenedAndSaved
FormatC#WhenOpenedAndSaved

FormatC#WhenOpenedAndSaved

Harshana Codes

|
3 installs
| (1) | Free
Automatically formats C# files with CSharpier when opened or saved.
Download

Format C# When Opened and Saved

Format C# When Opened and Saved is a lightweight Visual Studio extension that automatically formats C# files using CSharpier whenever a file is opened or saved.

The extension is designed for developers who want consistent C# formatting without having to manually run a formatter or remember extra commands. When a .cs file is saved, the extension sends the document content to CSharpier, applies the formatted result back to the editor, and saves the updated file. When a C# file is opened, the extension can also format the document automatically so files are cleaned up as soon as they are accessed.

Features

  • Automatically formats C# files on save
  • Automatically formats C# files when opened
  • Uses CSharpier for consistent, opinionated C# formatting
  • Works directly with the active Visual Studio document buffer
  • Avoids formatting non-C# files
  • Prevents recursive save/format loops
  • Includes an Output window pane for troubleshooting
  • Runs formatting asynchronously to reduce Visual Studio UI impact

How It Works

When Visual Studio loads the extension, it subscribes to document open and save events. For each C# document, the extension reads the current editor text, runs CSharpier, and replaces the document contents only when formatting changes are detected.

Diagnostic messages are written to the Visual Studio Output window under:

CSharpier Auto Format

This makes it easier to confirm when formatting runs successfully or to troubleshoot CSharpier installation and command-line issues.

Requirements

CSharpier must be available to the project being formatted. You can install CSharpier globally:

dotnet tool install -g csharpier

Or install it as a local .NET tool in the repository you want to format.

After installing CSharpier globally, restart Visual Studio so the extension can resolve the updated tool path.

Recommended Use

This extension is useful for teams or individual developers who want automatic C# formatting without manually invoking CSharpier. It is especially helpful when working across large solutions where consistent formatting should happen naturally as files are edited and saved.

Troubleshooting

Open Visual Studio’s Output window and select:

CSharpier Auto Format

The extension logs initialization, formatting success, skipped files, and CSharpier errors there.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft