Every now and then I come across a weird build error, with a simple but highly unintuitive fix.
Generally when something somewhere has been configured to do something ugly :D
Obviously I fix it "properly" if I can, and I document the fix if I can't ... but really what I want to do is in the .csproj write something akin to:
catch(Exception thisSpecificBuildErrorWithCodeXXXOrMessageYYY)
{
log.Error("You've done PPPPP, which causes an error because QQQQQQ. The build is going to fail and the way that you fix it is by doing RRRRRR");
throw;
}
So that the message is immediately present for the next dev that stumbles across it.
Does MSBuild have anything resembling that?
Team IDE is Rider, and we're using .NET vLatest, if relevant.
When an MSBuild task is executed, the task returns true
if it was succesful, and false
otherwise. When a task fails, the caller of a task won't know the reason why. The task can generate messages, warnings, and errors as output (that can be logged) but there is no general feature or facility in MSBuild to scan the output of a task (e.g. the Csc task) for specific errors.
You can create a custom logger. You would need to build the logger assembly. Then you need to build your project specifying the assembly of the custom logger. That might be impractical in some situations.
It may be simpler to run the build and then have a script that scans the log from the build.
But instead of catching a compiler error, is there a verification or test that can be performed before running the compiler? Is there is a particular pattern of "something ugly" that can be tested for?
You can add a custom target to your .csproj that performs the verification. Use BeforeTargets="BeforeBuild"
to set the target to execute early in the target order. Use the Error task to report a failed verification. You would have complete control of the content of the error message.