我想从SonarQube分析中排除GlobalSuppressions.cs
文件,以便它不会查看那里的System.Diagnostics.CodeAnalysis.SuppressMessage
指令。
这些是在每个项目的根目录中,但不在解决方案所在的根目录中:例如
我在admin中设置了这个:
即**/GlobalSuppressions.cs
。
每个解决方案中都有很多项目,所以我希望尽可能避免单独引用每个项目。
答案 0 :(得分:0)
我对此问题的解决方案是使用Powershell脚本清除globalsupressions.cs
文件并将规则集从错误(CodeAnalysisRulesErrors.ruleset
或CodeAnalysisRulesUnitTestsErrors.ruleset
)更改为发出警告的规则集( CodeAnalysisRules.ruleset
或CodeAnalysisRulesUnitTests.ruleset
),SonarQube正确地报告了技术债务。
[CmdletBinding()]
param (
[string]$localWorkspace
)
begin{}
process
{
try
{
$localWorkspace = "$($env:SYSTEM_DEFAULTWORKINGDIRECTORY)\$($localWorkspace)"
$localWorkspace = $localWorkspace -replace "/" , "\"
$localWorkspace = $localWorkspace -replace "\\" , "\"
Write-Verbose $localWorkspace
#Work out top level directories, excluding system dirs
[System.Collections.ArrayList]$topLevelDirs = @()
$topLevelItem = Get-ChildItem $localWorkspace -Exclude @("node_modules", "packages", "Common", ".nuget", ".vs", "_Resharper.Caches", "Javascript")
foreach ($item in $topLevelItem)
{
if (Test-Path $item -PathType Container) {
Write-Verbose $item
$topLevelDirs.Add($item)
}
}
foreach ($topLevelFolder in $topLevelDirs)
{
Write-Verbose $topLevelFolder
$ServiceDirs = Get-ChildItem -Path $topLevelFolder -Filter GlobalSuppressions.cs -Recurse
foreach ($sd in $ServiceDirs)
{
Write-Verbose $sd
Clear-Content $sd.FullName
}
Get-ChildItem -Path $topLevelFolder -Filter *.csproj -Recurse | ForEach {
Write-Verbose $_.FullName
(Get-Content $_.FullName | ForEach { $_ -replace 'CodeAnalysisRulesErrors.ruleset', 'CodeAnalysisRules.ruleset' }) | Set-Content $_.FullName
(Get-Content $_.FullName | ForEach { $_ -replace 'CodeAnalysisRulesUnitTestsErrors.ruleset', 'CodeAnalysisRulesUnitTests.ruleset' }) | Set-Content $_.FullName
}
}
}
catch
{
write-host "Caught an exception:"
write-host "Exception Type: $($_.Exception.GetType().FullName)"
write-host "Exception Message: $($_.Exception.Message)"
}
}
end{}