如何使用控件和窗体的Visual Studio访问TFS版本控制窗体、如何使用、控件、版本

2023-09-04 23:29:02 作者:只愿得一人心

从命名空间中的类 Microsoft.TeamFoundation.Client 和 Microsoft.TeamFoundation.VersionControl.Client 就可以访问Team Foundation Server的版本控制(TFS- VC)编程。

With the Classes from the namespaces Microsoft.TeamFoundation.Client and Microsoft.TeamFoundation.VersionControl.Client it is possible to access the Team Foundation Server Version Control (TFS-VC) programatically.

时,也可​​以使用中所使用的Visual Studio中在自己的应用程序的控制和形式?它看起来像极了类中的 Microsoft.TeamFoundation.VersionControl.Controls 标记为内部的,因此不能用外...

Is it also possible to use the Controls and Forms that are used in Visual Studio in an own application? It looks like most of the classes in Microsoft.TeamFoundation.VersionControl.Controls are marked as internal and therefore not available outside...

推荐答案

这是可能的,下面我用TFS2010,发现它somehwere在互联网上,它打开了SourceControlFileSelector:

It is possible, the following I used for TFS2010 and found it somehwere in the internet, it opens the SourceControlFileSelector:

                VersionControlServer versionControlServer = (VersionControlServer)tfsConnection.GetService(typeof(VersionControlServer));
                Assembly controlsAssembly = Assembly.GetAssembly(typeof(Microsoft.TeamFoundation.VersionControl.Controls.ControlAddItemsExclude));

                Type vcChooseItemDialogType = controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogChooseItem");
                ConstructorInfo ci = vcChooseItemDialogType.GetConstructor(
                                   BindingFlags.Instance | BindingFlags.NonPublic,
                                   null,
                                   new Type[] { typeof(VersionControlServer) },
                                   null);
                _chooseItemDialog = (Form)ci.Invoke(new object[] { versionControlServer });
                _chooseItemDialog.ShowDialog();
                this.DialogResult = _chooseItemDialog.DialogResult;


                _selectItemProperty = vcChooseItemDialogType.GetProperty("SelectedItem", BindingFlags.Instance | BindingFlags.NonPublic);
                Item selectedItem = (Item)_selectItemProperty.GetValue(_chooseItemDialog, null);

有关TFS2012有一些对话框直接使用,如TeamProjectPicker:

For TFS2012 there are some dialogs directly usable, like the TeamProjectPicker:

        TeamProjectPicker dp = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false);
        DialogResult dr = dp.ShowDialog();
        if (dr.Equals(DialogResult.OK) && dp.SelectedTeamProjectCollection != null)
        {
            Name = dp.SelectedTeamProjectCollection.ConfigurationServer.Name;
            configTfsUrl = dp.SelectedTeamProjectCollection.ConfigurationServer.Uri.AbsoluteUri;
            tfsUrl = dp.SelectedTeamProjectCollection.Uri;
        }