Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 1.86 KB

generate-usings.md

File metadata and controls

49 lines (34 loc) · 1.86 KB
title description ms.date ms.topic author ms.author manager ms.subservice dev_langs helpviewer_keywords
Generate usings
Learn how to use the Quick Actions and Refactorings menu to immediately add the necessary imports or using directives for copy-and-pasted code.
03/10/2020
reference
mikadumont
midumont
mijacobs
general-ide
CSharp
VB
add missing usings

Add missing usings in Visual Studio

This code generation applies to:

  • C#

  • Visual Basic

What: Lets you immediately add the necessary imports or using directives for copy-and-pasted code.

When: It's common practice to copy code from different places in your project or other sources and paste it in to new code. This Quick Action finds missing imports directives for copy-and-pasted code and then prompts you to add them. This code fix can also add references from project to project.

Why: Because the Quick Action automatically adds necessary imports, you don't need to manually copy the using directives that your code needs.

Add missing usings refactoring

  1. Copy code from a file and paste it into a new one without including the necessary using directives. The resulting error is accompanied by a code fix that adds the missing using directives.

    [!NOTE] You need to enable this suggestion in Tools > Options > Text Editor > C# > Advanced > Using Directives.

  2. Select Ctrl+. to open the Quick Actions and Refactorings menu.

    Generate usings

  3. Select using <your reference>; to add the missing reference.

    Generate usings result

See also