Automatically fix fixable errors
Some errors in the error list could be automatically fixed. For instance, you build your code and the error "The type 'bla' is not referenced. You must add a reference to assembly 'System.Data.Entity'" appears in the error pane. This error is easily fixed by adding the correct reference to the project, but since Studio already knows what it's looking for, it knows where it's located (GAC), why isn't there an option to fix it?
It would be nice if the error pane would have a column "Autoresolve" with for each error which migh be fixable a link "Try resolving". Studio would then try to autoresolve the problem, for instance by adding the correct reference to the project and all would be well. If there was a problem resolving the problem, Studio could display an error message telling the user the autofix didn't work and he should correct the problem himself.
In the same category, auto fixes could be applied for things like missing/extra parentheses, ; characters, etc. etc. I think the list of autoresolvable things is actually pretty long.
But please note: VS should NEVER do this on it's own. It should always be the developers action to perform an autoresolve.
Hi supporters of this issue
As has been noted by some commenters to this issue, we introduced the Light Bulb capability in Visual Studio:
This addresses some of the feedback on this thread, and new lightbulb “fixers” are appearing with every release. The lightbulb allows you to apply the same fix to other issues of the same type in the document, project or solution too, so bulk fixing is easy.
We don’t currently expose this feature directly in the error list, but you can always use F8/Shift-F8 to move between errors in the list and Ctrl+. to invoke the light bulb.
I’m resolving this item as completed since the main thrust of the request has been met, so you can all have your votes back for other items. If you have other feedback, e.g. about fixers you’d like to see implemented or having the ability to fix items directly from the error list (“lightbulbs in the error list”), please feel free to create a new item and vote it up.
Program Manager, Visual Studio IDE Team
Martijn Hoekstra commented
VS already has some autofix (press ctrl-. on the line with the error and autofixes show up) but I do like the addition of being able to do this in the problems window (with some sensible behaviour: focus the window on the line in question, show a dialog with options), and I very very much would like adding a reference to a project in the current solution to be autofixible.
Benjamin Howarth commented
Also add missing using; statements. I'm walking through 200 build errors simply adding one line to each and every single file, and the IDE knows where to find the class already.
Add missing included in C++ code. In that case, it could be added at the end by default and the line be automatically selected so that we can move it elsewhere easily if desired.
Madushan Siriwardena commented
remove unused using statements when building.. (They're pretty easy to add ... just CTRL+. but normally forget to remove and gets the top of the file cluttered.)
Also, 'fix ';' expected' compile error automatically..
Also remove unused references automatically (or add that option in the tools) upon pre-release builds.
David Ledbetter commented
In VB some some references are given, others you have to figure them out on your own.