我對這個問題的解決方案是使用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{}