locked
Find the tfs through the extension RRS feed

  • Question

  • Hi,

    Through a VS Extension how can I read the sln file to get the TFS it is bound to or is there any other way to get the tfs path from the sln file

    Tuesday, November 18, 2014 4:43 PM

Answers

  • Hi Uday,

    If the solution is opened in the VS IDE, Team Explorer will automatically connect to the TFS server which binds to the solution. So we can use the DTE object to get the SourceControlExt object, then retrieve the TFS server information from its properties. Code sample is here(I used VSPackage project):

    VersionControlExt vce;
            VersionControlExplorerExt vcee;
            private void MenuItemCallback(object sender, EventArgs e)
            {
                
    
                DTE2 dte=GetService(typeof(SDTE)) as DTE2;
                dte.ExecuteCommand("View.TfsSourceControlExplorer");
                vce = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
    
                vcee = vce.Explorer;
    
                var tfsServerName = vcee.Workspace.VersionControlServer.TeamFoundationServer.Name;
            }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Uday Mandava Wednesday, November 19, 2014 5:12 PM
    Wednesday, November 19, 2014 8:22 AM

All replies

  • Hi Uday,

    If the solution is opened in the VS IDE, Team Explorer will automatically connect to the TFS server which binds to the solution. So we can use the DTE object to get the SourceControlExt object, then retrieve the TFS server information from its properties. Code sample is here(I used VSPackage project):

    VersionControlExt vce;
            VersionControlExplorerExt vcee;
            private void MenuItemCallback(object sender, EventArgs e)
            {
                
    
                DTE2 dte=GetService(typeof(SDTE)) as DTE2;
                dte.ExecuteCommand("View.TfsSourceControlExplorer");
                vce = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
    
                vcee = vce.Explorer;
    
                var tfsServerName = vcee.Workspace.VersionControlServer.TeamFoundationServer.Name;
            }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Uday Mandava Wednesday, November 19, 2014 5:12 PM
    Wednesday, November 19, 2014 8:22 AM
  • Hi Zhong,

    THank you for the code snippet, but I want to load the solution and find out if that solution is bound or not. For the snippet you provided if I open the Source Control Explorer and parallelly create a new solution even then it works. I do not want this to happen.

    Monday, November 24, 2014 7:32 PM
  • Hi Uday,

    I just consulted some TFS engineer, and find out that TFS doesn't store any information in the solution files. So you can't find the TFS server information from the Solution itself. But if the solution folder is under the control of the TFS source control, the root folder should belongs to a workspace. We can check if the solution folder is in some workspace with this code snippet:

    using Microsoft.TeamFoundation.Client; 
    using Microsoft.TeamFoundation.VersionControl.Client;
    
    WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(@"C:\Users\username\Desktop\JTest-Scrum2013\EmptyProject3\test.txt");
    TfsTeamProjectCollection tfsc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(wi.ServerUri);
    TfsConfigurationServer configurationServer = tfsc.ConfigurationServer;
    Console.WriteLine(configurationServer.Uri);

    You can firstly get the solution path:

    dte.Solution.FullName

    replace the parameter of GetLocalWorkspaceInfo method with the solution path, if the Uri is empty, it means that the solution is not under the control of TFS.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 25, 2014 10:22 AM