IamIC
IamIC

Reputation: 18259

Visual Studio "Organize Usings | Remove and Sort" falsely reports error

In various code files of various projects, Visual Studio sometimes gives an error message when I tell it to remove and sort the usings of the code file. The message:

"Your project or one of its references does not currently build. If you continue with this operation, required usings may be removed."

However, this is not true. Required usings are not removed when telling VS to continue, and the project does build.

I have Googled this issue, looked in MSDN, and tried to figure out why I get this on certain code files but not others, but no no avail.

Has anyone else encountered this, and if so, any ideas what this is about?

Ps. I am running VS 2012 Ultimate, but I saw this from at least 2005.

Upvotes: 22

Views: 2989

Answers (2)

Steve Cadwallader
Steve Cadwallader

Reputation: 2736

This error message can come up erroneously, and is a known issue documented out on Microsoft Connect:

http://connect.microsoft.com/VisualStudio/feedback/details/785457/remove-unused-usings-falsely-reports-that-project-does-not-build-for-certain-files

It will not be fixed with the current MSBuild compiler, but will be fixed with Roslyn.

Workaround:

You can disable the warning message by going to Tools->Options->Text Editor->C#->Advanced->"Warn if build errors exist when organizing usings".

Keep in mind this has the downside that it won't protect you any more if your solution really does not build.

Upvotes: 18

Nick Smith
Nick Smith

Reputation: 126

I had this same issue and it turned out there was an invalidly formatted class reference in an XML comment. I had something like this

<see cref="List{T">

Note the missing '}' character at the end. It was driving me crazy until I found that.

Note: I'm using Visual Studio 2012 with the Productivity Power Tools installed, and this was happening every time I saved because I had the "remove and sort usings on save" option turned on. I really like this feature and was on the point of turning it off due to these warnings, thinking it was buggy. Now I know what to look for when I get them.

Upvotes: 8

Related Questions