Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / WPF

Building The Code Project Add-In for Visual Studio 2008

Rate me:
Please Sign up or sign in to vote.
3.91/5 (5 votes)
24 Jun 2009CPOL3 min read 30.1K   38   6
Harnessing the wealth of information found on CodeProject.com from within the Visual Studio IDE.

Background

With every new release of Visual Studio, Microsoft has given developers additional tools to help them do their jobs more quickly and effectively. The single most useful of these tools has been the Visual Studio SDK which gives developers the ability to create add-ins. Such add-ins can be used to deliver additional features and functionality from within the confines of the IDE. The degree of flexibility given to add-in developers is tremendous – almost every facet of Visual Studio can be monitored and controlled with relative ease. In fact, the hardest part of writing a Visual Studio add-in is probably thinking up a useful piece of functionality to merit an add-in!

We all know that any good developer spends at least a few minutes a day on CodeProject.com. A good number of those visits are driven by programming problems which surface while developing, so it makes perfect sense to allow developers to harness the wealth of information found on CodeProject.com from within the Visual Studio IDE itself. That is exactly the premise on which The Code Project Add-In for Visual Studio 2008 was built. Download your copy here: http://www.codeproject.com/services/addins/.

Getting Started

To create a new add-in project, go to File -> New Project -> Other Project Types -> Extensibility, and select Visual Studio Add-in.

Image 1

Name your project and click OK. This will start the Add-in Wizard. Click Next to get underway.

Image 2

Select your preferred development language. You will then be prompted to choose a development language and whether the add-in should be able to run in the VS.NET IDE or the Macro IDE or both. In our case, we choose both for Visual Studio 2008.

Image 3

Image 4

Next, we enter a name and a one-line description for the add-in. We’re almost there.

Image 5

Step 4 of 6 is the Add-in Options dialog. This dialog allows for the creation of a corresponding item in the Tools menu as well as determining when the add-in loads and who can use it.

Screen 5 of 6 is used to populate the Help About information box.

Image 6

The very last dialog box is a confirmation screen showing options selected so far. Click Finish, and you’re ready to begin.

Image 7

Off the bat, your Solution Explorer will look like this:

Image 8

This is the basis of your Visual Studio add-in project and all you need to get cracking with your idea. Of course, the overwhelming majority of add-ins will require UI elements to be put in place to allow users to interact with and use them. The Visual Studio SDK allows for these elements to be easily created and placed throughout the IDE. However, if you’re looking for a slightly snazzier, more modern UX presence, you are going to need more than the basic UI styles and elements supported in the Visual Studio SDK. Enter XAML. The Code Project add-in features eye candy and a cleaner UI/UX experience made possible by WPF/XAML. Getting that into play requires a little more tinkering than we’ve already done.

In keeping with sound software design principles, we separate concerns; we create a separate project for the WPF UI that is to be the add-in’s front end. Once you have created a WPF project, you can begin styling it and implementing its various UI behaviors. I would strongly advise manipulating the XAML for your Window (and any subsequent controls nested in it) in Blend as it provides both flexibility and responsiveness for these tasks that VS simply does not. Once you have your WPF/XAML looking and behaving as desired, simply nest all of that content in a regular user control that will in turn be integrated into Visual Studio. We take this approach as XAML is not yet fully supported in the Visual Studio SDK.

Bridging the VS-SDK XAML Divide

To achieve this, you will need to create a user control as follows with the XAML controls being created programmatically and injected in:

C#
public partial class CodeProjectSearchControl : 
       UserControl, IVsRunningDocTableEvents, IOleCommandTarget
{
    /// <summary>
    /// override the OnLoad event
    /// </summary>
    /// <param name="e"></param>
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (GlobalVariables.DTE == null)
            GlobalVariables.DTE = this.GetEnviroment();

        // create the search panel control
        // create the ElementHost control for hosting the WPF UserControl.
        ElementHost host = new ElementHost();
        host.Dock = DockStyle.Fill;

        // Create the WPF UserControl
        this.uc = new SearchPanelControl();
        this.uc.SetDTE(GlobalVariables.DTE);

        host.Child = this.uc;

        this.pnlSearch.Controls.Add(host);

        // create the ad rotator control
        ElementHost adhost = new ElementHost();
        adhost.Dock = DockStyle.Fill;

        AdRotator aduc = new AdRotator();
        aduc.SetDTE(GlobalVariables.DTE);

        adhost.Child = aduc;

        this.pnlProperty.Controls.Add(adhost);
    }
}

Image 9

These two projects in tandem take care of the wire up of the UI to the add-in, and now you are free to add functionality and WPF verve to your own Visual Studio add-ins!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer CodeProject Solutions
Canada Canada
The CodeProject team have been writing software, building communities, and hosting CodeProject.com for over 20 years. We are passionate about helping developers share knowledge, learn new skills, and connect. We believe everyone can code, and every contribution, no matter how small, helps.

The CodeProject team is currently focussing on CodeProject.AI Server, a stand-alone, self-hosted server that provides AI inferencing services on any platform for any language. Learn AI by jumping in the deep end with us: codeproject.com/AI.
This is a Organisation

4 members

Comments and Discussions

 
GeneralDetect Proxy Pin
Md. Marufuzzaman14-Feb-10 3:42
professionalMd. Marufuzzaman14-Feb-10 3:42 
GeneralNow where have I seen this... Pin
SlickEdit Inc.25-Jun-09 9:09
SlickEdit Inc.25-Jun-09 9:09 
GeneralRe: Now where have I seen this... Pin
yshrestha25-Jun-09 9:32
yshrestha25-Jun-09 9:32 
Thanks for taking the time to comment!

Once an add-in project has been created using the wizard and a WPF project created and wired into the add-in project that's really the hard part done. Each WPF control has its functionality implemented in an appropriate project and is serviced outside/without the VSSDK. The point of this piece was to talk about the small step of bridging the gap between WPF and VSSDK not to talk about either the VSSDK or WPF. For this reason I didn't get heavily into the implemntation.

I checked out your CP browser too, very nice!

If I were you, who would be reading this?

GeneralRe: Now where have I seen this... Pin
Anna-Jayne Metcalfe29-Jun-09 20:45
Anna-Jayne Metcalfe29-Jun-09 20:45 
GeneralWeb Browser Window Pin
joutlaw24-Jun-09 15:19
joutlaw24-Jun-09 15:19 
GeneralRe: Web Browser Window Pin
yshrestha25-Jun-09 9:32
yshrestha25-Jun-09 9:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.