다음을 통해 공유


Quick Actions

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Quick Actions let you easily refactor, generate, or otherwise modify code with a single action. Quick Actions are available for C#, C++, and Visual Basic code files. Some actions are specific to a language, and others apply to all languages.

Quick Actions can be used to:

  • Suppress a code analyzer rule violation

Note

This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Refactoring (Visual Studio for Mac).

Quick Actions can be applied by using the light bulb light bulb icon or screwdriver screwdriver icon icons, or by pressing Ctrl+. when your cursor is on a line of code for which an action is available. You'll see an error light bulb error light bulb icon if there's a red squiggle indicating an error and Visual Studio has a fix available for that error.

For any language, third parties can provide custom diagnostics and suggestions, for example as part of an SDK, and Visual Studio light bulbs appear based on those rules.

Icons

The icon that appears when a Quick Action is available gives an indication of the type of fix or refactoring that's available. The screwdriver screwdriver icon icon indicates just that there are actions available to change the code, but you shouldn't necessarily use them. The yellow light bulb light bulb icon icon indicates there are actions available that you should do to improve your code. The error light bulb error light bulb icon icon indicates there's an action available that fixes an error in your code.

To see a light bulb or screwdriver

If a fix is available, light bulbs appear:

  • When you hover the mouse at the location of an error

    Light bulb with mouse hovering

  • In the left margin of the editor when you move the caret (cursor) into the applicable line of code

You can also press Ctrl+. anywhere on a line to see a list of available Quick Actions and refactorings.

To see potential fixes, select either the down arrow next to the light bulb or the Show potential fixes link. A list of available Quick Actions is displayed.

Light bulb expanded

See also