用于MSBuild的SonarQube扫描仪:排除

问题描述 投票:3回答:2

在SonarQube runner中,可以通过声纳项目属性中的sonar.exclusions属性管理排除的项目。这样我们就可以管理与代码库分开的构建配置。

我们正在从跑步者迁移到MSBuild的扫描程序,以便利用在我们的代码上运行FXCop规则。

将sonar-project.properties文件保留在项目的根文件夹中会导致“MSBuild.SonarQube.Runner.exe end”命令中出现异常。 SonarQube Scanner for MSBuild无法理解sonar-project.properties文件。从以下文件夹中删除这些文件:[文件夹]

我现在可以看到的排除特定项目的唯一选项(实际上所有名称以.Test,.Tests,.Testing,.UnitTests等结尾的项目)似乎是将项目属性添加到每个受影响项目中的propertyGroup:<SonarQubeExclude>true</SonarQubeExclude>与管理根级别(我们为jenkins做的)或构建设置(我们目前在TeamCity中使用)中的设置相比,难以维护,容易出错且繁琐。

还有其他选择吗?还是计划未来?

当项目文件夹被调用***。测试时,它仍然在将其添加到排除设置后进行扫描。

[14:14:14][Step 12/23] INFO: -------------  Scan MyProject.Tests
[14:14:14][Step 12/23] INFO: Excluded sources for coverage: 
[14:14:14][Step 12/23] INFO:   **/*.Tests/**/*
[14:14:14][Step 12/23] INFO:   **/*.Test/**/*
[14:14:14][Step 12/23] INFO: Base dir: C:\SomeFolder\MyProject\Modules\MyProject.Tests
[14:14:14][Step 12/23] INFO: Working dir: C:\SomeFolder\MyProject\.sonarqube\out\.sonar\{Sonar_Project}_{some guid}
[14:14:14][Step 12/23] INFO: Test paths: [I removed some classes], Utils/SomeTests.cs, Enum/dummy.resx, app.config, Compression/TestData/data1.FRM, Compression/TestData/data1.zip, Compression/TestData/data1.Off.zip, packages.config
[14:14:14][Step 12/23] INFO: Source encoding: UTF-8, default locale: en_US
[14:14:14][Step 12/23] INFO: Index files
[14:14:15][Step 12/23] INFO: 45 files indexed
[14:14:15][Step 12/23] INFO: Quality profile for cs: [some profile]
[14:14:15][Step 12/23] INFO: Quality profile for vb: [some profile]
sonarqube sonarqube-scan
2个回答
1
投票

没有关于在分析参数中管理这些属性组的文档,因为很难做到正确。相反,您应该使用UI来管理排除项:管理>常规设置>分析范围。

更多信息,see the docs


0
投票

对于那些感兴趣的人......经过一年多的时间,我们还没有找到替代方案,所以我们坚持以下解决方法,我们在构建之前添加到我们的TeamCity构建步骤中的一个小的PowerShell脚本,它负责添加属性group将项目从Sonar分析排除到以Tests.csproj结尾的项目文件:

$dir = "C:\Temp\ExcludeProjectsFromSonar"

Get-ChildItem $dir *Tests.csproj -recurse | 
% { 
   $root = [xml](gc $_.FullName);
   $project = $root.Project;

   $propertyGroup = $root.CreateElement("PropertyGroup", $project.NamespaceURI);
   $comment = $root.CreateComment("Exclude the project from analysis");
   $sonarExclude = $root.CreateElement("SonarQubeExclude", $project.NamespaceURI);
   $sonarExclude.InnerText = 'true';

   $propertyGroup.AppendChild($comment);   
   $propertyGroup.AppendChild($sonarExclude);
   $project.AppendChild($propertyGroup);

   $root.Save($_.FullName);
}
© www.soinside.com 2019 - 2024. All rights reserved.