I would look to hook into the output of msbuild (and/or dotnet build).
I've found a way of getting the text passed to the output window in Visual Studio. I can write a Visual Studio Extension (VSIX) that contains an IClassifier. If I add an IClassifierProvider
like this:
[ContentType("output")]
[Export(typeof(IClassifierProvider))]
public class MyClassifierProvider : IClassifierProvider
{
public IClassifer GetClassifier(ITextBuffer textBuffer)
{
return new MyClassifer();
}
}
Then in the MyClassifier
:
public class MyClassifier : IClassifier
{
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
// I will get the build output here, line by line
}
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
}
So I can get the build output in the GetClassificationSpans
method, but it means I need to return a classification of the line. I'm not interested in this. I just want to capture the build output and do something else with it. For example, I could want to write all warnings to a file.
This makes me wonder if the IClassifier
route is the way to go.
I thought I could hook into some Roslyn API, but from what I read, this is useful to analyze the code. What I want is to get the complete build output, with all statements (i.e. what you see in the Output window).
So now I'm looking at writing a VSIX, but don't think IClassifier
is my best option.