简体   繁体   中英

How to use the Controls and Forms of Visual Studio to access the TFS Version Control

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.

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...

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM