I'm trying to convert an existing command line tool into msbuild custom task.
This tool logs messages and errors using the System.Console class.
I've added to the tool's assembly a class that inherits from Microsoft.Build.Utilities.Task and calls the tool main function, and the custom tool works fine - but no messages/errors are displayed (on the Visual Studio output window).
I would like to avoid changing the original tool's code (otherwise I could change every "Console.Error.WriteLine" to "Log.LogError"). I thought of changing the stdout and stderr streams of console by calling Console.SetOut and SetError before calling the tool's main function. For that, I would need to implement a class that inherits from TextWriter.
So my questions are:
- Why System.Console writes aren't automatically sent to Log of BuildSystem?
- Is inheriting from TextWriter and setting the streams of Console - a good solution for this problem?
- Perhaps someone already did this work and wrote a TextWriter implementation for sending output/error to the msbuild log?
- If not, where can I find some reference code that gives an example of a class that implements TextWriter?
Thanks.