在 Visual Studio 外部使用 VersionControlExt.Explorer

发布于 2024-08-19 04:58:43 字数 1548 浏览 2 评论 0原文

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

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

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

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

这里尝试在 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);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飘过的浮云 2024-08-26 04:58:43
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 });
        }
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 });
        }
血之狂魔 2024-08-26 04:58:43

事实证明我并不真正需要那个资源管理器。

我通过使用 TreeView 控件和 VersionControlServer.GetItems() 来完成此操作。

代码片段如下:

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

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);
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文