在Visual Studio扩展中打开标准对话框

时间:2012-11-02 17:16:43

标签: c# visual-studio-2012 visual-studio-extensions vsix

我正在撰写Visual Studio扩展程序,并希望在点击时打开连接到Team Foundation Server 标准对话框。

我能够使用像DTE2.ExecuteCommand("Team.ConnecttoTeamFoundationServer")这样的DTE2.ExecuteCommand方法,但我觉得必须有更好的方法来使用Visual Studio宏。

非常感谢任何帮助。提前谢谢!

1 个答案:

答案 0 :(得分:2)

您可以使用Team Project PickerMicrosoft.TeamFoundation.Client程序集。这个blog给出了如何使用它的完整细节。我在下面粘贴,上面的博客文章中的示例代码将帮助您显示对话框。

private static TfsTeamProjectCollection _tfs;
private static ProjectInfo _selectedTeamProject;

// Connect to TFS Using Team Project Picker
public static void ConnectToTfsUsingTeamProjectPicker()
{
     // The  user is allowed to select only one project
     var tfsPp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);

     tfsPp.ShowDialog();

     // The TFS project collection
     _tfs = tfsPp.SelectedTeamProjectCollection;

     if (tfsPp.SelectedProjects.Any())
     {
          //  The selected Team Project
          _selectedTeamProject = tfsPp.SelectedProjects[0];
     }
 }