1

I'm implementing StyleCop in a .NET project that started 2 years ago and that had no code conventions, no static analysis.

After configuring the rules I want to use in StyleCop and ran it I got several thousands of warnings (I will omit the actual number because it would overflow the StackOverflow site :)).

The point is: since I cannot fix all the warnings in a moment, I want to setup some kind of "thresold" to avoid more violations, and I want to implement it as a post action build in MSBuild.

Now, the question is: is it possible to get the number of warnings in MSBuild and generate an Error Task if that number is bigger than some limit?

The mechanism must be available both in MSBuild and VisualStudio, since the IDE is the most common tool developers use in their daily work (that's why I don't want to write a script that takes MSBuild output, parse it and raise an error if the warning limit is reached).

Am I solving the wrong problem or facing the problem wrongly in your opinion? Have you ever faced some situation like this?

Luis
  • 2,833
  • 3
  • 27
  • 41
  • Possible duplicate of [How can I treat MSB3245 (could not resolve reference) warning as an error?](http://stackoverflow.com/questions/17495278/how-can-i-treat-msb3245-could-not-resolve-reference-warning-as-an-error) – stijn Aug 01 '16 at 18:43
  • I'm not sure that solution fits to my case, since I want it to work in VisualStudio as well, but I'll use it to continue my research. – Luis Aug 01 '16 at 19:20
  • 1
    It seems that it is not possible to do what I'm trying to do, according to http://stackoverflow.com/questions/38708356/specify-a-logger-in-msbuild-configuration-file, so I cannot count warnings in Visual Studio. My feeling now is that VS sucks :( – Luis Aug 01 '16 at 22:12
  • 1
    Thinking an entire IDE sucks because one super-specific tiny bit is not implemented - with reason I guess - is a couple of bridges too far for me, but I agree it would have been nice if it were possible to interact with the logging in VS directly. However your *that's why I don't want to write a script that takes MSBuild output* claim is wrong imo: you can have per-project build log files in VS as well, so if you add a project which runs after all other projects and have it parse those log files your problem is fixed, no? – stijn Aug 02 '16 at 07:24
  • Seems not a clean, bright solution to me. I'll implement some script to parse the output of MSBuild but leave VS with no insight about the "warning barrier" issue, since it has no support to even get the output of the build (and yes I think this is a big issue for me, VS has poor support for hard stuff regarding automation and scripting, the same as PowerShell, TFS and Windows) Sometimes I feel like playing with children toys when using Microsoft products. All cool and bright features but nothing to improve automation, performance of the IDE (very poor and getting worse version after version). – Luis Aug 02 '16 at 14:00
  • *it has no support to even get the output of the build* but it does, in the form of a logfile, see previous comment? – stijn Aug 02 '16 at 14:54

0 Answers0