Run Code Analyzers in VSTS project build

时光总嘲笑我的痴心妄想 提交于 2019-12-24 10:58:58

问题


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).


回答1:


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.

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

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


来源:https://stackoverflow.com/questions/47188775/run-code-analyzers-in-vsts-project-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!