0

I'm developing a TFS tool to assist the developers in our company.

This said tool needs to be able to "browse" the TFS server like in the Source Control Explorer. I believe that by using VersionControlExt.Explorer.SelectedItems, a UI will pop-up that will enable the user to browse the TFS server (please correct me if I'm wrong).

However, VersionControlExt is only accessible when developing inside Visual Studio (aka Plugin). Unfortunately, I am developing a Windows Application that won;t run inside VS.

So the question is, Can I use VersionControlExt outside of Visual Studio? If yes, how?

Here's an attempt on using the Changset Details Dialog outside of 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);
Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
Ian
  • 5,625
  • 11
  • 57
  • 93
  • Just curious, why not use the web version provided by MS, included in the default install with TFS2010 as well: http://msdn.microsoft.com/en-us/teamsystem/bb980951.aspx I'm curious because we have a similar situation, what needs did the web version not meet? – Nick Craver Jan 22 '10 at 13:31
  • There are plans to also incorporate this tool on our Build System. Note that our Build System is from year 1995 and that still uses batch files (not TFS Build System). – Ian Jan 24 '10 at 09:29

2 Answers2

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 });
        }
Patrick S
  • 11
  • 3
0

Turns out that I don't really need that Explorer.

I accomplished this by using the TreeView control and VersionControlServer.GetItems().

Code snippet below:

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

Then, everytime the user expand the nodes, I get all the items under that 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);
                }
Ian
  • 5,625
  • 11
  • 57
  • 93