Using Directives Sorted in Wrong Order

旧巷老猫 提交于 2019-11-28 19:28:02

问题


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.


回答1:


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

Then change the following setting:

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.'



来源:https://stackoverflow.com/questions/12715340/using-directives-sorted-in-wrong-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!