如何使用DTE从VS 2015/2017的错误列表中获取错误代码?或者其他方式可以得到错误代码?

时间:2017-01-16 02:32:35

标签: c# visual-studio-2015 envdte

我想扩展Visual Studio 2015/2017中的错误列表,我只使用DTE可以获取ErrorItem但是ErrorItem不包含ErrorCode就像下面一样,我怎样才能得到错误代码?提前致谢! enter image description here

1 个答案:

答案 0 :(得分:0)

是的,我也有这个。可能来不及帮忙,但是你走了:

    var errorList = _dte.ToolWindows.ErrorList as IErrorList;
    // placed in dictionary for easy access later
    var entries = (errorList?.TableControl.Entries ?? Enumerable.Empty<ITableEntryHandle>())
        .Select((e, i) => new { Entry = e, Index = i + 1 })
        .ToDictionary(it => it.Index, it => it.Entry);

    var errors = errorList.ErrorItems;
    for (int i = 1; i <= errors.Count; i++)
    {
        ErrorItem error = errors.Item(i);
        entries[i].TryGetValue("errorcode", out var errorCode);
        var item = new
        {
            error.Column,
            error.Description,
            error.ErrorLevel,
            error.FileName,
            error.Line,
            error.Project,
            Code = errorCode
        };
    }