简体   繁体   English

SonarQube MSBuild运行程序中的程序性覆盖排除项

[英]Programmatic coverage exclusions in SonarQube MSBuild runner

Is there a way to programatically exclude artifacts from Sonar analysis using the MSBuild Scanner? 有没有一种方法可以使用MSBuild Scanner以编程方式从Sonar分析中排除工件?

We have a number of different Visual Studio solutions in our git repository. 我们的git储存库中有许多不同的Visual Studio解决方案。 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. 我希望从这些常见项目中排除代码覆盖范围-但仅适用于某些Sonar项目。

Always excluding a project is straightforward and documented via adding a <PropertyGroup> section in the .csproj . 总是不包括一个项目是直截了当的并且记录通过添加<PropertyGroup>在部分.csproj

Adding the /d:sonar.coverage.exclusions="**/MyCommonCode/**" argument to the MSBuild scanner appears to do nothing, nor does adding exclusion patterns in Sonar itself. /d:sonar.coverage.exclusions="**/MyCommonCode/**"参数添加到MSBuild扫描器似乎无济于事,也没有在Sonar本身中添加排除模式。

Rationale 基本原理

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. 如果通用代码具有100,000行并且经过了良好的测试,但是我的项目只有10,000行并且具有零测试,那么Sonar代码覆盖范围将是人为有利的。

Instead, I intend to have a separate Sonar project containing just the coverage of this common code. 相反,我打算有一个单独的Sonar项目,其中仅包含此通用代码的内容。

We are using SonarQube 7.0, and the SonarScanner for MSBuild 4.0.2. 我们正在使用SonarQube 7.0和用于MSBuild 4.0.2的SonarScanner。

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 eg 您可以将条件添加到您所引用的MSBuild片段中,并使用该条件来控制是否在分析中包含公共项目,例如

<PropertyGroup> <!-- Exclude the project from analysis --> <SonarQubeExclude Condition="$(ExcludeCommonCode)=='true'" >true</SonarQubeExclude> </PropertyGroup>

...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. ...然后将参数/ p:ExcludeCommonCode = true传递给MSBuild,以生成您不想分析其通用代码的解决方案。

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. 以这种方式排除普通项目并不仅仅是将那些项目排除在代码范围之外:这意味着根本不会分析代码(没有问题,也没有指标),并且这些MSBuild项目不会出现在该SonarQube项目下所有。 However, I guess this is what you want if you have a separate SonarQube project for analysing the common projects. 但是,如果您有一个单独的SonarQube项目来分析常见项目,那么我想这就是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用带有MSBuild Runner的C#插件的SonarQube不会进行排除 - SonarQube with C# plugin with MSBuild Runner does not take exclusions SonarQube MSBuild Runner默认为h2数据库 - SonarQube MSBuild Runner defaults to h2 Database SonarQube MSBuild运行器因禁用规则而失败 - SonarQube MSBuild runner fails on deactivated rule MSBuild.SonarQube.Runner.Tool不分析.cs文件 - MSBuild.SonarQube.Runner.Tool not analyzing .cs files 具有MSBuild Runner的C#插件的SonarQube需要大量时间 - SonarQube with C# plugin with MSBuild Runner takes a lot of time MSBuild SonarQube Runner是否支持C ++项目? - Does the MSBuild SonarQube Runner support C++ projects? MSBuild.SonarQube.Runner.exe结束,PostProcessing失败退出代码1 - MSBuild.SonarQube.Runner.exe end, PostProcessing failed exit code 1 使用Jenkins和Sonarqube分析c#项目-调用MSBuild.SonarQube.Runner.exe结束时出错 - Analysis c# Project with Jenkins and Sonarqube - Error calling MSBuild.SonarQube.Runner.exe end MSBuild SonarQube Runner Resharper插件收到跳过信息错误文件不在sonarqube中 - MSBuild SonarQube Runner Resharper Plugin receives skipping info errors File not in sonarqube SonarQube MSBuild运行程序不适用于已添加到项目中的移植FxCop Roslyn规则 - SonarQube MSBuild runner isn't working with ported FxCop Roslyn rules added to projects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM