C# 在Visual Studio外部使用VersionControlText.Explorer
我正在开发一个TFS工具来帮助我们公司的开发人员 该工具需要能够像在源代码管理资源管理器中一样“浏览”TFS服务器。我相信,通过使用VersionControlExt.Explorer.SelectedItems,将弹出一个用户界面,允许用户浏览TFS服务器(如果我错了,请纠正我) 但是,只有在Visual Studio(又名插件)内部开发时,才能访问VersionControlText。不幸的是,我正在开发一个Windows应用程序,它赢了;不要在里面跑 所以问题是,我可以在VisualStudio之外使用VersionControlText吗?如果是,如何进行 尝试在Visual Studio外部使用“更改集详细信息”对话框C# 在Visual Studio外部使用VersionControlText.Explorer,c#,tfs-sdk,C#,Tfs Sdk,我正在开发一个TFS工具来帮助我们公司的开发人员 该工具需要能够像在源代码管理资源管理器中一样“浏览”TFS服务器。我相信,通过使用VersionControlExt.Explorer.SelectedItems,将弹出一个用户界面,允许用户浏览TFS服务器(如果我错了,请纠正我) 但是,只有在Visual Studio(又名插件)内部开发时,才能访问VersionControlText。不幸的是,我正在开发一个Windows应用程序,它赢了;不要在里面跑 所以问题是,我可以在VisualStu
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);
结果证明我真的不需要那个探险家 我通过使用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);
}
只是好奇,为什么不使用MS提供的web版本,也包括在TFS2010的默认安装中:我很好奇,因为我们有一个类似的情况,web版本没有满足什么需求?我们还计划在构建系统中加入此工具。请注意,我们的构建系统是从1995年开始的,并且仍然使用批处理文件(而不是TFS构建系统)。
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);
}