Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add all missing usings at once with Visual Studio 2019 and C#

When I write C#, I sometimes have 3-4 missing usings which I can add with the tooltip window -> add missing using, or doing ctrl + . On the line where a missing using is present.

Doing this 3-4 times is rather annoying.

I have noticed a "add all missing usings" tooltip sometimes, which worked, but I can not get it to pop up reliably.

I know resharper has it, but I don't want to use a paid extension for this feature.

How can I reliably get this "add all missing usings" pop up, or in what other way can I add all missing usings at once?

Thanks!

like image 521
S. ten Brinke Avatar asked Dec 19 '19 17:12

S. ten Brinke


2 Answers

The "add missing usings" is triggered by a paste action. After you paste new code, the option will be available so long as you haven't made any edits to the document after pasting the code (making any edit removes the option). Also, the option doesn't add missing usings for the rest of the document -it only analyzes the pasted section-.

You can cut out your code and then paste it to trigger the action as unfortunately currently it is not part of the default Quick Actions refactorings.

like image 165
rhytonix Avatar answered Oct 24 '22 07:10

rhytonix


To complete @rhytonix answer... after pasting your code, you have to click on the screwdriver in the left margin like this:

enter image description here

like image 3
A. Morel Avatar answered Oct 24 '22 05:10

A. Morel