SonarQube MSBuild运行程序中的程序性覆盖排除项 [英] Programmatic coverage exclusions in SonarQube MSBuild runner

查看:176
本文介绍了SonarQube MSBuild运行程序中的程序性覆盖排除项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使用MSBuild扫描仪以编程方式从Sonar分析中排除工件?

Is there a way to programatically exclude artifacts from Sonar analysis using the MSBuild Scanner?

我们的git存储库中有许多不同的Visual Studio解决方案。几乎所有这些解决方案都使用包含共享代码的项目。我希望将代码覆盖范围从这些常见项目中排除,但仅限于某些Sonar项目。

We have a number of different Visual Studio solutions in our git repository. Almost all of these solutions make use of projects containing shared code. I am wishing to exclude code coverage from these common projects - but only for certain Sonar projects.

总是排除项目很简单,并且记录,方法是添加< PropertyGroup> .csproj 中的c>部分。

Always excluding a project is straightforward and documented via adding a <PropertyGroup> section in the .csproj.

添加 /d:sonar.coverage MSBuild扫描程序的.exclusions = ** / MyCommonCode / ** 参数似乎无济于事,也没有在Sonar本身中添加排除模式。

Adding the /d:sonar.coverage.exclusions="**/MyCommonCode/**" argument to the MSBuild scanner appears to do nothing, nor does adding exclusion patterns in Sonar itself.

理论上

我希望为使用这些常见项目的代码保持准确的代码覆盖率指标。如果通用代码有100,000行并且经过了很好的测试,但是我的项目只有10,000行并且有零测试,那么Sonar代码覆盖范围将是人为有利的。

I am wishing to maintain accurate code coverage metrics for code using these common projects. If the common code had 100,000 lines and is well tested but my project only has 10,000 lines and has zero tests, the Sonar code coverage would be artificially favourable.

相反,我打算有一个仅包含此通用代码覆盖范围的Sonar项目。

Instead, I intend to have a separate Sonar project containing just the coverage of this common code.

我们正在使用SonarQube 7.0,以及用于MSBuild 4.0.2的SonarScanner。

We are using SonarQube 7.0, and the SonarScanner for MSBuild 4.0.2.

推荐答案

您可以在您所引用的MSBuild代码段中添加条件,并使用该条件来控制是否在分析中包括公共项目,例如

You could add condition to the MSBuild snippet you referred to, and use that to control whether the common projects are included in the analysis or not e.g.

< PropertyGroup>
< ;!-从分析中排除项目->
< SonarQubeExclude Condition = $(ExcludeCommonCode)==’true'> true< / SonarQubeExclude>
< / PropertyGroup>

...然后将参数 / p:ExcludeCommonCode = true 传递给MSBuild

...and then pass the argument /p:ExcludeCommonCode=true to MSBuild for the builds of the solutions for which you don't want to analyse the common code.

以这种方式排除普通项目的作用远不只是将这些项目排除在代码范围之外:这意味着根本不会分析代码(没有问题,没有指标),并且那些MSBuild项目根本不会出现在SonarQube项目下。但是,如果您有一个单独的SonarQube项目来分析常见项目,我想这就是您想要的。

Excluding the common projects in this way does more than just exclude those projects from code coverage: it means the code won't be analysed at all (no issues and no metrics), and those MSBuild projects won't appear under that SonarQube project at all. However, I guess this is what you want if you have a separate SonarQube project for analysing the common projects.

这篇关于SonarQube MSBuild运行程序中的程序性覆盖排除项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆