VS2013 - Package - C#
I want to read all errors/hints/warnings in the error window.
By following the example on MSDN concerning "ToolWindows.ErrorList Property"
I added this code to my package:
ErrorList errorList = dte.ToolWindows.ErrorList;
ErrorItems errorItems = errorList.ErrorItems;
string aString = string.Empty;
int countErr = errorItems.Count;
if (countErr != 0)
{
for (int i = 1; i <= countErr; i++)
{
aString += (errorItems.Item(i).Description.ToString() + "\n");
}
MessageBox.Show(aString);
}
else
{
MessageBox.Show("There are no items in the error list.");
}And it returned all standard build errors and warnings. However, I have StyleCop installed, and none of those warnings are returned. Why is that? I read a link somewhere about a package only being able to delete its own messages, but I'm not
trying to delete, just read. Is that still not allowed? I then found another post that suggested that a package could use a ErrorListProvider to retrieve errors as well. Here is the code I added to my package:
private void MenuItemCallback(object sender, EventArgs e)
{
DTE2 dte = (DTE2)GetService(typeof(DTE));
if (errorListProvider == null)
{
IServiceProvider serviceProvider = new ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
errorListProvider = new ErrorListProvider(serviceProvider);
errorListProvider.ProviderName = "My Package";
errorListProvider.ProviderGuid = new Guid(GuidList.guidMyPkgString);
}
int countErr = errorListProvider.Tasks.Count;
if (countErr != 0)
{
string aString = string.Empty;
foreach (ErrorTask task in errorListProvider.Tasks)
{
aString += (task.Text + "\n");
}
MessageBox.Show(aString);
}
else
{
MessageBox.Show("There are no items in the error list.");
}
}
This code complied and ran, but returned no errors at all. What am I doing wrong?
- Thanks