Bouke
Bouke

Reputation: 12138

Run Code Analyzers in VSTS project build

In VSTS (hosted TFS) I have a build definition which uses MSBuild. What I would really like is to have pull requests annotated with any rule violation detections. However I can't get the analysers to work at all. What I've done so far;

  1. Installed Microsoft.CodeAnalysis.FxCopAnalyzers in one of the projects that gets build
  2. Verified that running "Analyze Code" in Visual Studio does output rule violations
  3. All the *.ruleset files are not available on the self-hosted build agent, as it only has MSBuild installed (no full-fledged Visual Studio). For the same project as in point 1, I've also used a custom ruleset.
  4. I have also build the project on a hosted build agent (which has VS2017 installed), but also to no avail.

With all of the above, the build log / build overview in VSTS doesn't list any rule violations. It's my understanding that the code analysis should be run automatically and the output should appear on the build overview page (i.e. https://MYSITE.visualstudio.com/MYPROJECT/_build/index?buildId=XXX&_a=summary&tab=details).

Upvotes: 1

Views: 1388

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

The Code Analysis setting is based on the configuration and platform, so you need to make sure you build the project with the same configuration and platform that enabled code analysis on build.

enter image description here

enter image description here

You also could specify it in MSBuild Arguments of MSBuild task:

/p:RunCodeAnalysis=true;CodeAnalysisRuleSet=..\RuleSets\MyMixedRecommendedRules.ruleset

Upvotes: 2

Related Questions