Visual Studio 2013团队资源管理器扩展未显示

时间:2014-07-24 00:00:43

标签: visual-studio-2013 visual-studio-extensions team-explorer

我正在尝试在Visual Studio 2013中构建团队资源管理器的扩展。我在http://31og.com/post/getting-start-with-a-team-explorer-plugin-for-vs-2013-part-3找到了博客,其中介绍了添加导航项和页面的步骤,但是当我运行时项目我没看到扩展名。

输出中没有错误。我可以看到正在调用的构造函数,但没有任何内容添加到团队资源管理器中。

这是我们当前的代码:

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));
            }
        }
    }
}

关于为什么会发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:1)

当您连接到团队项目时,您将能够经常看到该按钮。验证CurrentContext属性是否不为null并且包含已连接的TFS上下文。

或者,您也可以验证构造函数中的serviceProvider字段是否为空。

可见性通常采用Invalidate方法处理,如下所示。我已在下面为我的Team Rooms extension实施。

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

相关问题