I have added an Inspections (.NET) build step to a TeamCity (v8) project consisting of a Visual Studio 2010 solution build step for a single dummy C# class.
The build step has failure conditions that are set to fail if I get any inspection Errors or Warnings.
My dummy class only generates 2 Suggestions but the build fails claiming
"Build failure on metric change: Number of inspection warnings is too large: 3".
Is there a way to make the TeamCity step ignore the Suggestions?
I enabled debug output and the step definitely has no Warnings in it:
<!-- Generated by InspectCode 2.0.0.0 -->
<Report ToolsVersion="2.0">
<Information>
<Solution>Demo.sln</Solution>
<InspectionScope><Element>Solution</Element></InspectionScope>
</Information>
<IssueTypes><IssueType Id="InconsistentNaming" Category="Constraints Violations" Description="Inconsistent Naming" Severity="SUGGESTION"/>
<IssueType Id="UnusedMember.Global" Category="Redundancies in Symbol Declarations" Description="Type or type member is never used: Non-private accessibility" Severity="SUGGESTION"/>
</IssueTypes>
<Issues>
<Project Name="Demo">
<Issue TypeId="UnusedMember.Global" File="Demo\Class1.cs" Offset="36-42" Line="3" Message="Class 'Class1' is never used"/>
<Issue TypeId="UnusedMember.Global" File="Demo\Class1.cs" Offset="71-76" Line="5" Message="Field 'maybe' is never used"/>
<Issue TypeId="InconsistentNaming" File="Demo\Class1.cs" Offset="71-76" Line="5" Message="Name 'maybe' does not match rule 'Fields (not private)'. Suggested name is 'Maybe'."/>
</Project>
</Issues>
</Report>
The dummy class is as follows:
namespace Demo
{
public class Class1
{
public bool maybe = true;
}
}
Note that I still want Suggestions and Hints reported in Visual Studio so changing all non-Warnings and Errors to Do Not Report in the ReSharper settings is not an option (or creating and maintaining such a settings file solely for TeamCity to use).
This is still not possible with TeamCity 9 (it starts to get embarrassing for JetBrains, as this feature is really a joke without being able to limit only to warnings and errors).
But there is a do-it-yourself workaround
Using the free Resharper Command Line Tool "inspectcode" it is possible to generate an XML report for all Resharper issues:
This report still contains all issues, but it is then possible to throw an XPath query at the report to count the number of errors and warnings.
Here is how I do it in a Psake build file:
}
As you can see, I also had to filter out spurious
InconsistentNaming
warnings, but you could remove that part if you don't need it.And you could of course use a similar xpath query in an XSLT transformation to get rid of all non-warnings and non-errors. This way, you could use TeamCity to process the resulting file and display it as code inspection result.