71

I'm using the Power Commands extension with Visual Studio 2012. I have the option checked to remove and sort usings on save. The problem is that the System.Xxx directives are being sorted last, and that's causing a style analysis error:

SA1208: System using directives must be placed before all other using directives.

Before save:

using System;
using System.Diagnostics.CodeAnalysis;
using Foo;

After save:

using Foo;
using System;
using System.Diagnostics.CodeAnalysis;

This worked correctly (System.Xxx first) with VS 2010. Anyone know how to correct this?

Note: Even if it didn't cause an SA error, I'd still prefer the system directives to be first.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Bob Horn
  • 33,387
  • 34
  • 113
  • 219
  • Is there a VS2012 version of PowerCommands yet? This might be an issue that needs attention and thus worth reporting. – Jeff B Oct 03 '12 at 19:27
  • Reinstalling Powercommands 2010 even if its installed will apply it for VS2012 as well, AFAIK there is no 2012 Version of powercommands, regarding VS2013 it seems to be part of the pwoer tools now. – CloudyMarble Mar 11 '14 at 05:52
  • See here for more information: http://stackoverflow.com/questions/12156921/powercommands-for-visual-studio-2012 – CloudyMarble Mar 11 '14 at 05:53

1 Answers1

151

Goto the "Quick Launch" (Ctrl+Q) and type "using" and press Enter.

Then change the following setting:

Using Sorting option

It's an annoying default setting, I have no idea why Microsoft chose that, it goes against all previous standards that I've ever seen.

EDIT: Thanks to Oskar we have a reason:

The reason for the change in default behavior is due to the fact that Windows App Store applications prefer to have 'Windows.' at the top of the file rather than 'System.'

Community
  • 1
  • 1
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • 10
    I've found an answer to why Microsoft change the default behavior: "The reason for the change in default behavior is due to the fact that Windows App Store applications prefer to have 'Windows.*' at the top of the file rather than 'System.*'" (https://connect.microsoft.com/VisualStudio/feedback/details/775702/organize-usings-no-longer-puts-system-references-first-bug-or-feature-change) – Oskar Apr 04 '13 at 15:14
  • 2
    Thanks for the hint with Ctrl+Q and typing "using"! – Alex Klaus Aug 28 '15 at 01:48
  • @Oskar, it appears that your link is now dead. Do you have any other official source for this info? – julealgon Jun 27 '18 at 14:32