question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting "using" statements puts `System` namespaces first

See original GitHub issue

Issue Description

When saving a file in VS Code, it is formatted to place the System namespaces first. I don’t want this, and can’t find where to turn it off.

In Visual Studio (not Code), this can be turned off in the settings, but I can’t find where to disable this “feature” in VS Code.

Steps to Reproduce

Make a file and put these using statements at the top:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;

Expected Behavior

They are untouched because they are being used. I like my using statements alphabetical with nothing more.

Actual Behavior

They are reordered to place the System namespaces first:

using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Logs

OmniSharp log

Post the output from Output-->OmniSharp log here

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.62.3 C# Extension: 1.23.16

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa

.NET SDKs installed: 3.1.415 [C:\Program Files\dotnet\sdk] 5.0.403 [C:\Program Files\dotnet\sdk] 6.0.100-rc.1.21458.32 [C:\Program Files\dotnet\sdk] 6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk] 6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
better-cpp-syntax jeff-hykin 1.15.10
better-toml bungcip 0.3.2
code-spell-checker streetsidesoftware 2.0.13
cpptools ms-vscode 1.7.1
cpptools-extension-pack ms-vscode 1.1.0
crates serayuzgur 0.5.10
csharp ms-dotnettools 1.23.16
gitlens eamodio 11.7.0
godot-tools geequlim 1.1.2
hexeditor ms-vscode 1.8.2
indent-rainbow oderwat 8.2.2
language-x86-64-assembly 13xforever 3.0.0
markdown-preview-enhanced shd101wyy 0.6.1
material-icon-theme PKief 4.11.0
midl-webidl-syntax dave-deletethis 0.0.1
mono-debug ms-vscode 0.16.2
npm-intellisense christian-kohler 1.4.0
nugetpackagemanagergui aliasadidev 1.1.9
platformio-ide platformio 2.4.0
python ms-python 2021.11.1422169775
remote-ssh ms-vscode-remote 0.66.1
remote-ssh-edit ms-vscode-remote 0.66.1
remote-wsl ms-vscode-remote 0.58.5
rust-analyzer matklad 0.2.826
sort-imports amatiasq 6.2.6
tabnine-vscode TabNine 3.5.1
v4pvhdlforprofessionals ViDE-Software 1.1.2
vscode-eslint dbaeumer 2.2.2
vscode-firefox-debug firefox-devtools 2.9.5
vscode-npm-script eg2 0.3.23
vscode-nuget-package-manager jmrog 1.1.6
vscode-print pdconsec 0.9.14
vscode-pull-request-github GitHub 0.32.0
vscode-pylance ms-python 2021.11.2
vscode-tailwindcss bradlc 0.7.2
vscode-typescript-next ms-vscode 4.6.20211126
vscode-yaml redhat 1.2.1
vscodeintellicode VisualStudioExptTeam 1.2.14
vsliveshare ms-vsliveshare 1.0.5090
vsliveshare-audio ms-vsliveshare 0.1.91
wavetrace wavetrace 1.1.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JoeRobichcommented, Nov 29, 2021

@colejohnson66 You can configure the behavior of Organize Imports by changing settings within your .editorconfig file. See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#organize-using-directives for more details.

Below is an example which will disable sorting system directives to the top.

root = true

# .NET formatting rules
[*.{cs,vb}]
dotnet_sort_system_directives_first = false
dotnet_separate_import_directive_groups = false
0reactions
colejohnson66commented, Feb 21, 2022

Mmhm. You are correct. That was the issue! My apologies for the non-issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatically place the 'System' directives first when 'Sorting ...
Right Click on the Editor, and either select “Sort Usings” or “Remove and Sort” from the “Organize Usings' context menu. Organize Usings. Consider...
Read more >
VS2012 Sort Usings doesn't move System Usings first?
When I rightclick->Organize Usings->Sort Usings, every using is just sorted alphabetically. I'm expecting the System usings to be first.
Read more >
Sort usings - Visual Studio (Windows) - Microsoft Learn
Select Edit from the menu bar. · Select Intellisense > Sort Usings. Sort usings · You can also configure different settings for using...
Read more >
C# Namespace Ordering Coding Convention
In order to have VS put the System namespaces first when you sort and remove (the way StyleCop wants it) you need to...
Read more >
C# Sort Usings - Visual Studio Marketplace
sort.usings.order : Put namespaces in proper order. Values should be splitted with space. "System" by default. sort.usings.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found