May 20, 2019
Hot Topics:

Extending Visual Studio 2005

  • April 24, 2006
  • By Vijay Mehta
  • Send Email »
  • More Articles »

Make It Really Go!

You have successfully created a button, but it at this point it doesn't really do anything, so let's walk through an example which reads the errors in the Error List window and writes them to a file. Let's say that you working on a .Net project and you want to keep a running log of the errors you receive when you compile. Well, after we are done with the example all you will have to do after you compile is click on the "X" button you just created to write the errors to a running log file.

The wizard has already hooked up an event handler in the Initialize method of VsPkg.cs so you already have a callback method named MenuItemCallback. The wizard has also added some sample implementation code in the callback method, which pops up a message box.

IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
Guid clsid = Guid.Empty;
int result;
    ref clsid,
                  "Inside {0}.MenuItemCallback()", this.ToString()),
    0,        // false
    out result);

As you can see, when working with the SDK the syntax is a little different than what you are used to in the .Net framework.

After removing the generated code from the MenuItemCallback method you can add the following code which creates a generic IList, gets the pointer to the SVsErrorList interface, enumerates the tasks, and calls the WriteLog method to dump the results to disk.

IList tasks = new List();

IVsTaskList iel = (IVsTaskList)GetService(typeof(SVsErrorList));

IVsEnumTaskItems enumTaskItems;
iel.EnumTaskItems(out enumTaskItems);
int result;

uint[] fetched = new uint[1];
   IVsTaskItem[] taskItems = new IVsTaskItem[1];

   result = enumTaskItems.Next(1, taskItems, fetched);

   if (fetched[0] == 1)
       IVsTaskItem taskItem = taskItems[0] as IVsTaskItem;

} while (result == 0 && fetched[0] == 1);


Although this example is fairly simple, it does provide a good starting point for integrating all sorts of cool applications into the IDE. You can even extend this example by integrating the error logging into the event system of the IDE, so your errors are automatically logged when you compile. (Note: the entire source code for the package is available for download at the end of this article).

In conclusion, I know that I have only glazed over many of the topics and left out many others (i.e., deployment, toolwindows, editors, Domain Specific Languages, etc.). However, as an introduction to the hugely massive VS SDK I hope my articles have opened your eyes to the possibilities and the power of the VS SDK.


Source code: VSExtensibility.zip - 22 kb

About the Author

Vijay P. Mehta works as a technical consultant in Indiana, where he uses VS.NET to design, develop, and architect enterprise solutions. Reach him at vijay@mehtasolutions.com.

Page 3 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date