0

使用命名空间Microsoft.TeamFoundation.ClientMicrosoft.TeamFoundation.VersionControl.Client中的类,可以以编程方式访问 Team Foundation Server 版本控制 (TFS-VC)。

是否也可以在自己的应用程序中使用 Visual Studio 中使用的控件和表单?看起来Microsoft.TeamFoundation.VersionControl.Controls中的大多数类都被标记为内部的,因此在外部不可用......

4

1 回答 1

2

有可能,以下我用于 TFS2010 并在互联网上找到了它,它打开了 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:

        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;
        }
于 2013-07-24T13:55:51.930 回答