1
votes

I'm trying to build an extension to the team explorer in Visual Studio 2013. I've found the blog at http://31og.com/post/getting-start-with-a-team-explorer-plugin-for-vs-2013-part-3 which goes through the steps for adding a navigation item and a page but when I run the project I do not see the extension.

There are no errors in the output. I can see the constructor being called but nothing is added to team explorer.

Here is our current code:

namespace UoA.Cecil.VsTools.WindowPanes
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using Microsoft.TeamFoundation.Controls;
    using Microsoft.VisualStudio.Shell;

    [TeamExplorerNavigationItem(TeamExplorerGuids.TimesheetNavigationItem, 100)]
    public class TimesheetTeamExplorerNavigationItem
        : ITeamExplorerNavigationItem
    {
        private readonly IServiceProvider serviceProvider;
        private bool isVisible;

        [ImportingConstructor]
        public TimesheetTeamExplorerNavigationItem([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public Image Image
        {
            get { return Resources.TimesheetImage; }
        }

        public bool IsVisible
        {
            get { return this.isVisible; }
            private set
            {
                this.isVisible = value;
                this.FirePropertyChanged();
            }
        }

        public string Text
        {
            get { return "Timesheet"; }
        }

        public void Dispose()
        {
        }

        public void Execute()
        {
            // Do something here
        }

        public T GetService<T>()
        {
            if (this.serviceProvider != null)
            {
                return (T)this.serviceProvider.GetService(typeof(T));
            }
            return default(T);
        }

        public void Invalidate()
        {
        }

        private void FirePropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

Any ideas on why this would be happening?

1

1 Answers

1
votes

You will be able to see the button often when you are connected to the Team Project. Verify if CurrentContext property is not null and carries your connected TFS context.

Alternatively, you can also verify if your serviceProvider field in the constructor is not null.

The visibility is usually handled in Invalidate method as below. I have implemented below for my Team Rooms extension.

public override void Invalidate() { if (CurrentContext != null && CurrentContext.HasCollection && CurrentContext.HasTeamProject) { IsVisible = true; } else { IsVisible = false; } }