2016-06-15 174 views
2

我想從SonarQube分析中排除GlobalSuppressions.cs文件,以便它不會在那裏查看System.Diagnostics.CodeAnalysis.SuppressMessage指令。如何讓SonarQube忽略GlobalSuppressions.cs文件?

這些位於每個項目的根目錄中,但不在解決方案所在的根目錄中:例如, enter image description here

我設置爲admin:

enter image description here

也就是說,**/GlobalSuppressions.cs

每個解決方案都有很多項目,所以我想盡可能避免單獨引用每個項目。

回答

0

我對這個問題的解決方案是使用PowerShell腳本來清​​除globalsupressions.cs文件,並從一個出錯(CodeAnalysisRulesErrors.rulesetCodeAnalysisRulesUnitTestsErrors.ruleset)一個拋出警告(CodeAnalysisRules.rulesetCodeAnalysisRulesUnitTests.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{}