问题描述
Sonarqube 允许通过在 sonar.coverage.exclusions 键中添加模式来将单个文件排除在代码覆盖范围之外.这可以通过将它们添加到 UI 甚至 .csproj 文件中(通过指定 SonarQubeSetting 元素)在项目级别上完成.即
Sonarqube allows for individual files to be excluded from code coverage by adding patterns in the sonar.coverage.exclusions key. This can be done on a project level by adding them in the UI and even in a .csproj file by specifying a SonarQubeSetting element. I.e.
<SonarQubeSetting Include="sonar.coverage.exclusions"><值>**/*.cs</值></SonarQube 设置>
但是,这两种方法似乎都不起作用.使用 SonarQube 文档中指定的模式不提供想要的结果.我也知道 SonarQubeExclude MSBuild 属性的存在,但我不想走这条路,因为它会将我的项目排除在所有其他分析之外.
However, both of these approaches don't seem to work. Playing with the patterns, as specified in the SonarQube documentation doesn't provide the desired result. I'm also aware of the existence of the SonarQubeExclude MSBuild property, but I don't want to go down that path as it would exclude my project from all other analysis.
还有另一种我失踪的可能性吗?还是根本不可能将项目中的所有类都排除在代码覆盖范围之外?
Is there another possibility that I'm missing? Or is it simply not possible to exclude all of the classes within a project from code coverage?
推荐答案
总结上面的答案,也加一点.
Summing up the above mentioned answers and also adding one point to it.
要从 csproj 中排除 SonarQube 分析中的项目,我们可以通过在该项目的 .csproj 中添加以下代码来实现
To exclude a project from SonarQube Analysis from csproj we can achieve by adding the below code in .csproj of that project
<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
从项目中排除文件
To exclude a file from a project
<ItemGroup>
<SonarQubeSetting Include="sonar.coverage.exclusions">
<Value>**/FileName.cs</Value>
</SonarQubeSetting>
</ItemGroup>
对于多个文件
And for multiple files
<ItemGroup>
<SonarQubeSetting Include="sonar.coverage.exclusions">
<Value>**/FileName1.cs, **/FileName2.cs</Value>
</SonarQubeSetting>
</ItemGroup>
也可以参考 正则表达式模式 使用过
这篇关于如何使 Sonarqube 从覆盖度量中排除 .NET (C#) 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)