Use Case: Building Add-ins for VS.NET

VisualStudio.Net has become a popular dev tool in large part because of its feature-rich structure and easy UI. However, it is not always easy to customize VS.NET. In this case study, Elementools CEO offers an insights, lessons learned (and sample code) on the best ways to adjust VS.NET to meet your individual dev needs.

Tags: Developers, Command, User Interface, Dim, Window, Add-in, Programmers,



Visual Studio.Net is a popular developer tool due to
its feature-rich structure and easy-to-use interface.



In particular, developers appreciate its easy access to
web services in the .net framework. However, one
challenge devs face is finding a means of tracking
issues within a project that is as streamlined as VS.NET itself.



Until its latest release, developers using VS.NET had to
exit the program browser and access an issues-tracking
tool in a separate window. The back-and-forth was
confusing, and hampered streamlined management of the
project and code-development issues.



The developer team for a web-services based bug tracking
technology company, Elementool, tackled the challenge,
ultimately developing a streamlined project management
tool that deployed directly in the VS.NET environment.
But developing add-ins for VS.NET is relatively
uncommon, and it is not an easy task. The following
case study, with sample code from the project,
illustrates the challenges faced in creating this
accessible solution.



The programming team's plan was to create an add-in tool
featuring four buttons at the top of the button bar.
The tool was to be integrated into the Visual Studio
interface and become part of the VS.NET software.
Ultimately, this would make it easier for programmers
to multi-task.



Initially, the programmers assumed the business logic for
VS.NET is the same as any Windows application, so the
logic for the add-in would be the same as well. But
that was not the case. The VS.NET user interface is
unique, and that made it difficult to interface off a
connection to the user interface toolbars. They
discovered that Microsoft does not supply the
component needed to build the user interface in Visual
Studio versions 2002 and 2003, although the component
is supplied in the 2005 version.



As a result, developing the user interface so the add-in
tool fully integrated into VS.NET through Windows was
a major challenge.



In the end, Elementool's programmers resolved this issue
by reaching out to other developers through a
newsgroup on Yahoo. Their questions were answered
quickly and professionally, although not all the
suggestions worked.



The magic bullet was supplied by one of Microsoft's "Most
Valuable Professionals" who is an active member in the
newsgroup.



Here is a sample of the code:



1) Adding a toolbar with a button on it:


Dim bar As CommandBar
'Add the toolbar
bar = applicationObject.DTE.Commands.AddCommandBar("myToolbar", vsCommandBarType.vsCommandBarTypeToolbar)
'put the toolbar on the top section
bar.Position = MsoBarPosition.msoBarTop
bar.Visible = True
'add a button to the toolbar
Dim btn As CommandBarButton = bar.Controls.Add()
btn.Caption = "toolbar button"

2) Adding a menu to the menu bar before the "tools" menu:

'Create contextGUIDS array of objects - need for creating commands
Dim contextGUIDS() As Object = New Object() {}
Dim menu As CommandBar = applicationObject.DTE.Commands.AddCommandBar("myMenu", vsCommandBarType.vsCommandBarTypeMenu, applicationObject.CommandBars("menubar"), applicationObject.CommandBars("MenuBar").Controls.Count - 4)
'add the menu item: create a command and add control for this command
Dim cmd As Command = applicationObject.Commands.AddNamedCommand(addInInstance, "myCommand", "myCommand", "myCommand", True, , contextGUIDS, CInt(vsCommandStatus.vsCommandStatusSupported) + CInt(vsCommandStatus.vsCommandStatusEnabled))
Dim btn As CommandBarButton = cmd.AddControl(menu, 1)

3) Opening a tool window and hosting .NET user control (NetCtl) on it using Microsoft's shim control (VSUserControlHost).
Dim obj As Object = Nothing  'the object that will be returned by CreateToolWindow 
'toolwindows are identified by GUIDs, we create a new GUID for the new window
Dim newWin As Window = applicationObject.Windows.CreateToolWindow(addInInstance, "VSUserControlHost.VSUserControlHostCtl", caption, Guid.NewGuid.ToString("B"), obj)
newWin.Visible = True ' set the new window to be visible
Dim objControl As VSUserControlHostLib.IVSUserControlHostCtl = obj
'host the .Net user control
objControl.HostUserControl(System.Reflection.Assembly.GetExecutingAssembly().Location, NetCtl.GetType.ToString)

In the end, Elementool's developer team learned a couple
important lessons from the experience. First, when
developing an add-in tool, most of the work will be
concentrated on the user interface. Second, the
knowledge you acquire may be applicable in other
areas. Developing the client applications for the bug-
tracking tool also made it easier for the developers
to use the company's existing web services. All in
all, persistence paid off.



Yaron Sinai is the CEO and founder of Elementool, a
leading provider of .NET-powered web based and web
services management tools such as help desk, bug and
defect tracking and time tracking tools. Over 50,000
subscribers around the world use Elementool technology
as the foundation of their project development and
testing processes. For additional information, please
visit www.elementtools.com





back