Skip to content

Instantly share code, notes, and snippets.

@RhysC
Created February 3, 2011 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RhysC/809361 to your computer and use it in GitHub Desktop.
Save RhysC/809361 to your computer and use it in GitHub Desktop.
Filter and sort FXCop warning from build output - Powershell
$buildfile = "build.log"
$outputfile = "FxCopList.csv"
$hash = @{} # used to filter duplicates
$fxcopFilter = "[CodeAnalysis]"
gc $buildfile |
%{if($_.contains($fxcopFilter) -and $_.contains(" CA")) {$_}} |
%{
$startindex = $_.IndexOf($fxcopFilter) + $fxcopFilter.Length;
$line = $_.SubString($startindex).TrimStart();
$line;
} |
%{
if($hash.$_ -eq $null){$_};
$currrentLine = $_;
$myobj = "" | Select codeAnalysisCategory,codeAnalysisId,description,file,fullDetails
$myobj.fullDetails = $_;
if($currrentLine.Indexof("CA") -ne 0)
{
if($currrentLine.Indexof(": CA") -gt 0)
{
$endindex = $currrentLine.IndexOf(": CA");
$myobj.file = $currrentLine.SubString(0,$endindex).TrimStart();
$currrentLine = $currrentLine.replace($myobj.file +":", "").Trim();
}
}
if($currrentLine.Indexof("CA") -ne 0)
{
Write-Error "error" -ForegroundColor Red
Write-Error $currrentLine -ForegroundColor Red
throw "I messed up. CA should be the start of this line"
}
$endindex = $currrentLine.IndexOf(" : ");
if($endindex -lt 0){ throw "codeAnalysisId could not be found for $_"}
$myobj.codeAnalysisId = $currrentLine.SubString(0,$endindex).Trim();
$currrentLine = $currrentLine.Replace($myobj.codeAnalysisId + " : ", "").Trim();
$endindex = $currrentLine.IndexOf(" : ");
if($endindex -lt 0){
Write-Warning "codeAnalysisCategory could not be found for $_";
$myobj.codeAnalysisCategory = "";
$myobj.description = $currrentLine;
}
else
{
$myobj.codeAnalysisCategory = $currrentLine.SubString(0,$endindex).Trim();
$myobj.description = $currrentLine.replace($myobj.codeAnalysisCategory + " : ", "").Trim();
}
$hash.$_ = 1
$myobj;
} |
Sort-Object codeAnalysisCategory, codeAnalysisId |
Export-Csv $outputfile
@RhysC
Copy link
Author

RhysC commented Feb 3, 2011

Build files from MSBuild/TeamCity are big, they have lots of stuff in them. I just want to extract distinct FXcop violation from them so I can montior the Code Quailty with out opening the solution... visual studio, i never though id miss you.
Basically this allows me to see where oour major issues are and assign specific tasks as a backlog item, eg Fix Capitialisation issues (of which there is 42 warnings)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment