My question is based on another one, but I want to do the opposite: tell msbuild to treat the warning as an error instead of suppressing a specific msbuild warning.
However, all I see so far says /p:WarningsAsErrors
only takes in csc warnings and errors. I tried just dropping the MSB
and googling for what number might go in there to work, but no luck.
Is there any way to treat an "assembly reference not found" warning from msbuild (command line) as an error?
Recently I needed something similar (acting on certain log events) but I couldn't find a clean solution mainly because I haven't figured out how to programmatically access the loggers in the msbuild process. I did come up with this though, adapted to your problem the principle is:
Might sound hard, but the code is simple enough:
Here's a sample msbuild script using it:
And you invoke it like this:
edit I just needed this again but couldn't find the original dll nor project file etc anymore - I figured storing just the code and simplest build instructions in git and building it on the fly when needing it is probably cleaner. So basically store the code above in a file customlogger.cs and then somewhere in your build process, before effectively invoking msbuild with the custom logger, build it using
update In response to comments: trying this again today I'm not sure the original code actually ever worked (well, it does for the sample message shown but not for actual warning MSB3245), since it hooks message events only whereas the ResolveAssemblyReference emits an actual warning event and moreover the warning number isn't typically contained contained in the message. This does the trick though:
It seems that the message associated with this warning that's not a warning:
, is not quite correct. If the missing reference is a WPF theme, you'll get a run-time error (System.IO.FileNotFoundException) instead.
As an aside, if you specifically look for MSB3245 you'll get: