Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Created July 26, 2012 23:59
Show Gist options
  • Save DinisCruz/3185313 to your computer and use it in GitHub Desktop.
Save DinisCruz/3185313 to your computer and use it in GitHub Desktop.
VisualStudio VSIX: Adding an item to the ErrorList
var vsixPackage = O2_FluentSharp_VSIXPackage.vsixPackage; // this is a reference to an Package object
var ivsSolution = (IVsSolution)Package.GetGlobalService(typeof(IVsSolution));
var dte = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(EnvDTE.DTE));
var errorListProvider = new ErrorListProvider(vsixPackage);
var errorText = "this is a test item";
var errorCategory = TaskErrorCategory.Error;
//Get first project details
var proj = dte.Solution.Projects.Item(1);
var projectUniqueName = proj.FileName;
var firstFileInProject = proj.ProjectItems.Item(1).FileNames[0];
//Get first project IVsHierarchy item (needed to link the task with a project)
IVsHierarchy hierarchyItem;
ivsSolution.GetProjectOfUniqueName(projectUniqueName, out hierarchyItem);
var newError = new ErrorTask()
{
ErrorCategory = errorCategory,
Category = TaskCategory.BuildCompile,
Text = errorText,
Document = firstFileInProject,
Line = 2,
Column = 6,
HierarchyItem = hierarchyItem
};
newError.Navigate += (sender,e)=>
{
//there are two Bugs in the errorListProvider.Navigate method:
// Line number needs adjusting
// Column is not shown
newError.Line++;
errorListProvider.Navigate(newError, EnvDTE.Constants.vsViewKindCode.guid());
newError.Line--;
};
errorListProvider.Tasks.Clear(); // clear previously created
errorListProvider.Tasks.Add(newError); // add item
errorListProvider.Show(); // make sure it is visible
return errorListProvider;
//using Microsoft.VisualStudio.Shell
//using Microsoft.VisualStudio.Shell.Interop
//using O2.FluentSharp.VSIX;
//O2Ref:O2_FluentSharp_VSIX.dll
//O2Ref:EnvDTE.dll
//O2Ref:EnvDTE80.dll
//O2Ref:Microsoft.VisualStudio.Shell.10.0.dll
//O2Ref:Microsoft.VisualStudio.Shell.Interop.dll
//O2Ref:Microsoft.VisualStudio.OLE.Interop.dll
//O2Ref:Microsoft.VisualStudio.Shell.Interop.8.0.dll
//O2Ref:Microsoft.VisualStudio.Shell.Interop.9.0.dll
//O2Ref:Microsoft.VisualStudio.Shell.Interop.10.0.dll
//generateDebugSymbols
@shekharsingh1987
Copy link

Dear Dinis,
I have referred your code for adding errors to Errorlist window of Visualstudio. Thanks you and appreciate.
Everything was fine but how can i add Error Id Which appears under Code column in Error list.
image

@Enache-Ionut
Copy link

Enache-Ionut commented Mar 7, 2018

Hi,

I'm interested in how to fill Code field of an error too. I'm adding manually errors in error list but the Code field is empty.
In my extension I'm writing errors in VS output window in the next format :
filePath(line): type code : description

The type can be error, warning or message. In this way I can double click on an error from output window and VS allows me to navigate to the line of code where the error occurred. Is there any way to make VS error list to automatically get the errors from output window if them are written in the above mode?

@Enache-Ionut
Copy link

Enache-Ionut commented Jun 22, 2018

Hi,

Another problem about VS Error List is the order of the messages. I want the messages to be sorted like this: Errors, Warnings, Messages. I sorted my collection and I added them in order but the order is not kept. How can I make the Error List to keep my custom order or how to make it to order my custom errors in the above format?

@jckhoa
Copy link

jckhoa commented Mar 28, 2020

Hi,

I'm interested in how to fill Code field of an error too. I'm adding manually errors in error list but the Code field is empty.
In my extension I'm writing errors in VS output window in the next format :
filePath(line): type code : description

The type can be error, warning or message. In this way I can double click on an error from output window and VS allows me to navigate to the line of code where the error occurred. Is there any way to make VS error list to automatically get the errors from output window if them are written in the above mode?

Which command did you use to write to VS output window ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment