0

My overall goal is to read all warnings at the end of a solution build, then log them as errors. This is distinct from the TreatWarningsAsErrors setting, because this should also create binaries for projects that had those warnings.

I expect to solve this with a custom MSBuild task, but I don't know what I need to pass it from the .targets file.

EDIT: I don't think this is a duplicate of this question, because that addresses parsing the log for a certain string, and issuing an error for that specific code. I want to get a list of all warnings in the build, regardless of their content.

Community
  • 1
  • 1
Dahud
  • 171
  • 1
  • 8
  • 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) ; question looks somewhat different, but in the end it's the same: how to act on warnings emitted by logger during build. – stijn May 04 '17 at 19:23
  • stjin - that might be useful, but I don't want to just catch certain warnings. I want to catch all warnings. Since those can come in different forms, direct log parsing might not be enough. I'll try it though. – Dahud May 05 '17 at 13:55
  • As far as I know all warnings emitted by MS tools should match a case insensitive `warning [^:]+:` regex, which is easy enough to apply to the linked answer. And other tools better follow the same convention if they want their messages to behave in line with the res. – stijn May 05 '17 at 19:00

1 Answers1

0

You can't get build warnings from inside a task as it simply doesn't have access to this information. Warnings are raised and send to the MS Build logging infrastructure and handled there, which is totally divorced from the task execution.

You can however write a custom logger to track warnings emitted by the build. With your custom logger, whenever a warning event is raised, simply record it and then when the build completes you can do whatever you want with that information.

See the documentation here and here on how to write a custom logger.

Michael Baker
  • 3,338
  • 26
  • 29