Run code analysis manually for .NET

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

By default, .NET Compiler Platform ("Roslyn") analyzers analyze your C# or Visual Basic code as you type by doing live analysis, as well as during build. Hence, you would normally not require to manually trigger code analysis. However, there are some scenarios where you may want to manually trigger code analysis:

Note

Running code analysis manually requires Visual Studio 2019 version 16.5 or later

  • By default, live code analysis executes analyzers only for open files in Visual Studio. However, you may be interested in viewing code analysis warnings for all files in a specific project or solution. If so, you would want to trigger code analysis once on a project or a solution. Alternatively, you can enable continuous live code analysis to execute on entire solution. For more information, see How to: Configure live code analysis scope for managed code.
  • You may prefer on-demand code analysis execution workflow over continuous live analysis or build-time analysis. If so, you can disable analyzer execution during live analysis and/or build. For information about disabling analysis, see How to disable source code analysis. Then you would want to manually trigger code analysis once on a project or a solution.

Run code analysis manually

  1. In Solution Explorer, select the project.

  2. On the Analyze menu, select Run Code Analysis on Project Name.

Code analysis will start executing in the background. You should see the message Running code analysis for <project>... in the Visual Studio status bar towards the bottom-left corner. Once code analysis completes, the status message will change to Code analysis completed for <project>. Error list will soon refresh with all code analysis diagnostics.