0

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.

Peter
  • 13,733
  • 11
  • 75
  • 122
  • Does it have to be a VSIX? A custom logger also gets all output – stijn Apr 18 '18 at 10:19
  • Not necessarily actually. I was starting with a vsix, but I was thinking it would be good to be abke to use the cli too. – Peter Apr 19 '18 at 11:14
  • 1
    Here's a sample: https://stackoverflow.com/questions/17495278/how-can-i-treat-msb3245-could-not-resolve-reference-warning-as-an-error/17515854#17515854. Does more than you want probably, but it also show hoe to build the custom logger dll on the fly which is convenient as you don't usually want to check it in sourcecontrol. – stijn Apr 19 '18 at 17:04
  • I believe that's a good route I can take. If you post your comment as an answer, I'll gladly accept it. – Peter Apr 23 '18 at 06:50
  • Since I'd just be copy-pasting code maybe you can just delete this question or mark as duplicate of the other one? – stijn Apr 23 '18 at 12:45
  • Heh, good point. – Peter Apr 23 '18 at 13:42

0 Answers0