【问题标题】:Use VersionControlExt.Explorer outside Visual Studio在 Visual Studio 之外使用 VersionControlExt.Explorer
【发布时间】:2010-03-23 17:49:48
【问题描述】:

我正在开发一个 TFS 工具来帮助我们公司的开发人员。

该工具需要能够像在源代码管理资源管理器中一样“浏览”TFS 服务器。我相信通过使用 VersionControlExt.Explorer.SelectedItems,会弹出一个 UI,使用户能够浏览 TFS 服务器(如果我错了,请纠正我)。

但是,VersionControlExt 只能在 Visual Studio(又名插件)中开发时访问。不幸的是,我正在开发一个不能在 VS 中运行的 Windows 应用程序。

所以问题是,我可以在 Visual Studio 之外使用 VersionControlExt 吗?如果是,怎么做?

Here's 尝试在 Visual Studio 之外使用更改集详细信息对话框

string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Assembly vcControls = Assembly.LoadFile(path + @"\Microsoft.TeamFoundation.VersionControl.Controls.dll");
Assembly vcClient =   Assembly.LoadFile(path + @"\Microsoft.TeamFoundation.VersionControl.Client.dll");

Type dialogChangesetDetailsType = vcControls.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogChangesetDetails",true);
Type[] ctorTypes = new Type[3] {vcClient.GetType("Microsoft.TeamFoundation.VersionControl.Client.VersionControlSever"),

vcClient.GetType("Microsoft.TeamFoundation.VersionControl.Client.Changeset"), typeof(System.Boolean)};

ConstructorInfo ctorInfo = dialogChangesetDetailsType.GetConstructor(ctorTypes);
Object[] ctorObjects = new Object[3] {VersionControlHelper.CurrentVersionControlServer, uc.ChangeSet, true};
Object oDialog = ctorInfo.Invoke(ctorObjects);
dialogChangesetDetailsType.InvokeMember("ShowDialog", BindingFlags.InvokeMethod, null, oDialog, null);

【问题讨论】:

  • 只是好奇,为什么不用MS提供的网页版,TFS2010默认安装也包含在内:msdn.microsoft.com/en-us/teamsystem/bb980951.aspx我很好奇,因为我们也有类似的情况,网页需要什么版本不符合?
  • 我们还计划将此工具整合到我们的构建系统中。请注意,我们的构建系统是从 1995 年开始的,并且仍然使用批处理文件(不是 TFS 构建系统)。

标签: c# tfs-sdk


【解决方案1】:
public void ShowChangeSetDetails(Form owner, Changeset changeSet)
        {
            string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assembly vcControls = Assembly.LoadFrom(path + @"\Microsoft.TeamFoundation.VersionControl.Controls.dll");
            Assembly vcClient = Assembly.LoadFrom(path + @"\Microsoft.TeamFoundation.VersionControl.Client.dll");

            Type dialogChangesetDetailsType = 
                vcControls.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogChangesetDetails", true);

            MethodInfo methodInfo = 
                dialogChangesetDetailsType.GetMethod(
                    "ShowChangeset", 
                    BindingFlags.Static | BindingFlags.NonPublic, 
                    null, 
                    new Type[] { typeof(IWin32Window), changeSet.VersionControlServer.GetType(), changeSet.GetType(), typeof(bool) }, 
                    null);
            methodInfo.Invoke(null, new object[] { owner, changeSet.VersionControlServer, changeSet, true });
        }

【讨论】:

    【解决方案2】:

    原来我真的不需要那个 Explorer。

    我通过使用 TreeView 控件和 VersionControlServer.GetItems() 实现了这一点。

    下面的代码sn-p:

            treeView.Sort(); //Alphabetically ordered
    
            //Get Initial List of Projects
            try
            {
                ItemSet itemSet = vcs.GetItems(@"$/", RecursionType.OneLevel);
    
                foreach (Item item in itemSet.Items)
                {
                    if (item.ServerItem == @"$/") //Ignore self
                        continue;
    
                    TreeNode node = new TreeNode(item.ServerItem, new TreeNode[] { new TreeNode() });
                    node.Tag = item.ServerItem;
    
                    if (item.DeletionId != 0)
                        node.ForeColor = Color.Red;
    
                    treeView.Nodes.Add(node);
                }
            }
    

    然后,每次用户展开节点时,我都会得到该节点下的所有项目。

    TreeNode curNode = e.Node;
                    curNode.FirstNode.Remove(); //Remove blank dummy node
    
    
                    ItemSet items = vcs.GetItems(curNode.Tag.ToString(), VersionSpec.Latest, RecursionType.OneLevel, DeletedState.Any, ItemType.Folder);
    
                    foreach (Item item in items.Items)
                    {
                        if (item.ServerItem == curNode.Tag.ToString()) //Ignore self
                            continue;
    
                        string Name = System.IO.Path.GetFileName(item.ServerItem);
    
                        TreeNode node = new TreeNode(Name, new TreeNode[] { new TreeNode() });
                        node.Tag = item.ServerItem;
    
                        if (item.DeletionId != 0)
                            node.ForeColor = Color.Red;
    
                        curNode.Nodes.Add(node);
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      相关资源
      最近更新 更多