Phil Jollans
Phil Jollans

Reputation: 3769

"Run Code Analysis" does not run my code analyzer

I have written a code analyzer as part of my Visual Studio Package.

This corresponds to the instructions on this page except that it is part of my existing Package and not a stand-alone analyzer.

The analyzer registers itself to analyze the the SyntaxNode types StringLiteralExpression and InterpolatedStringExpression.

public override void Initialize ( AnalysisContext context )
{
  context.RegisterSyntaxNodeAction ( AnalyzeString, SyntaxKind.StringLiteralExpression, SyntaxKind.InterpolatedStringExpression ) ;
}

As described here

By default, live code analysis executes analyzers only for open files in Visual Studio.

This is correct. My analyzer runs on open files.

The same page continues:

Run code analysis manually

  • In Solution Explorer, click the project.

  • On the Analyze menu, click Run Code Analysis on Project Name.

Code analysis will start executing in the background. You should see the message Running code analysis for ... 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 . Error list will soon refresh with all code analysis diagnostic

In this case, my analysis does not run.

I have placed breakpoints in the constructor, the SupportedDiagnostics property get, the Initialize function and the analyze function itself. None of them are entered if I start the code analysis manually via the Analysis menu (or via the context menu in the solution explorer).

Is there some additional condition required to activate a code analyzer for the manual code analysis?

Upvotes: 1

Views: 2052

Answers (1)

remondo
remondo

Reputation: 388

I also encountered this weird issue. In my case, I used the "wrong" Developer Command Prompt. I installed VS Build tools after installing VS2017, which also installed the 2nd Developer Command Prompt.

The Start Menu shortcuts of the 2 Developer Command Prompt are as follows:

A: BuildTools (does not work!)

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"

B. VS Professional (works!)

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat"

I spent all afternoon trying to figure this out! :-(

Upvotes: 1

Related Questions