有可能,以下我用于 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;
}