This extension helps organize C# using
statements and is meant to replicate the sorting and cleanup behavior you may be familiar with from Visual Studio. It is an actively-supported, forked version of the abandoned CSharpFormatUsings extension that offers bug fixes, new features, and compatibility with the OmniSharp, Roslyn, and C# Dev Kit Language Servers.
- Removes unnecessary
using
directives (enabled by default but can be disabled) and duplicates. - Sorts
using
directives in alphabetical order and into groups by the first level of the namespace. - Can be triggered on save, via the right-click menu in the editor, or with the
Organize C# Usings
command in the Command Palette (can also be setup as a keyboard shortcut). - Inserts a configurable number of empty lines between sets of sorted using statements.
- Offers multiple configurable settings for formatting the
using
section (see "Extension Settings" below).
- 1.0.6: Fixed a bug that would prevent all unused usings from being removed on the first execution of the "Organize C# Usings" command. The line numbers returned by vs.languages.getDiagnostics were being misinterpreted. New unit tests around the removal of unused usings.
- 1.0.5: Adds support for running natively on save, improved handling of duplicate removal during cleanup, an output panel channel for debug output, and various improvements in source code.
- 1.0.4: Handles IDE0005 diagnostics for unused usings from Roslyn, enabling compatibility with the C# extension when OmniSharp is disabled.
- 1.0.3: Properly handles aliased
using
directives without breaking syntax such asusing [type] [variableName] = whatever
. Adds basic unit test coverage. - 1.0.2: Fixes editor jumpiness based on Microsoft's recommendation to use
TextEditorEdit.delete/insert
instead ofreplace
. - 1.0.1: Fixed editor jumpiness when running "Organize Usings" on files that require no changes.
- 1.0.0: Correctly removes unused usings when all of a class's usings are unnecessary, and resolves issues caused by extra blank lines between namespace groups.
sortOrder
: Sets the order of namespaces. Values should be space-separated. "System" by default.splitGroups
: Inserts a blank line between using blocks grouped by the first part of the namespace. Enabled by default.removeUnnecessaryUsings
: Removes unnecessaryusing
statements if true. Enabled by default.numEmptyLinesAfterUsings
: The number of empty lines preserved between theusing
directives and the code block.numEmptyLinesBeforeUsings
: The maximum number of empty lines before theusing
directives if there are characters (like comments) before them.
To auto-organize on saving a C# file, add the following to your settings.json
file:
"[csharp]": { "editor.codeActionsOnSave": [ "source.organizeImports" ] }
- Install node.js.
- Run
npm install
from project folder. - Run
vsce package
from project folder. Please make surevsce
is installed:npm install -g vsce
. - Install brand new packed *.vsix bundle through vscode plugins menu option "Install from VSIX".
Forked from CSharpFormatUsings (an abandoned extension that was last modified on Aug 22, 2020) in 2024, which was forked from CSharpSortUsings, which was forked from CSharpFixFormat.