Ask a questionAsk a question
 

AnswerHow to get changeset number from TFS 2008

  • Tuesday, October 27, 2009 12:56 PMmwaseemalvi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dear I want to get the code from source control by using changeset numbers in TFS 2008. I want to know if any utility or source code is available  so that I can easily develop or use existed code of utility. Actually I have some requirements related to get the changeset which are developer mark in TFS source Code.

    I need to develop utility by using following requirements.

    TFS Server Name (for establishing a connection)

    TFS User Name

    TFS password

    TFS Team Project Name

    Changeset #

    The utility have a button "Get source code" that will get only those files that are being checked in under a changeset #.


    If anybody have this kind of utility or have any idea agaist it. Please let me know or help me.


    Thanks


    M Waseem Alvi


    Software Configuration Management Engineer

Answers

  • Tuesday, October 27, 2009 2:42 PMDavid_Stanley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    This will get you the TFS and VC server objects.  From there use a ChangesetVersionSpec to access the items.  You will need to decide how you want to down load the items.  You can create a workspace and do a get, or you can query the items and do a item.downloadfile().

    NetworkCredential networkCredential = new NetworkCredential("username", "password", "domain");
    ICredentials credential = (ICredentials)networkCredential;
    
    TeamFoundationServer server = new TeamFoundationServer("http://servername:8080", credential);
    VersionControlServer vcServer = (VersionControlServer)server.GetService(typeof(VersionControlServer));
    
    
  • Thursday, October 29, 2009 5:01 AMRuiz YiModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Waseem,

    As David mentioned, you can create a workspace or just download the files.

    Way1: Create a workspace and then get

            try
            {
                VersionControlServer.GetWorkspace(spacename, "usermane");
                VersionControlServer.DeleteWorkspace(spacename, "username");
            }
            catch { }
    
            Changeset changeset = VersionControlServer.GetChangeset(changesetID);
            Workspace ws = VersionControlServer.CreateWorkspace(spacename);
            ws.CreateMapping(new WorkingFolder("$/TFSProject1/",@"D:\workspace"));
            ws.Get(changeset.Changes.Select(c=>c.Item.ServerItem).ToArray(),  new ChangesetVersionSpec(changesetID),RecursionType.Full, GetOptions.None);
    
    

    Way2 Just DownLoad Files, but you need to create the path.
    Changeset changeset = TFSModal.Instance.VersionControlServer.GetChangeset(changesetID);
            foreach (var change in changeset.Changes)
            {
                change.Item.DownloadFile("path");
            }
    

    Best Regards,
    Ruiz
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Sincerely, Ruiz Yi

All Replies

  • Tuesday, October 27, 2009 2:42 PMDavid_Stanley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    This will get you the TFS and VC server objects.  From there use a ChangesetVersionSpec to access the items.  You will need to decide how you want to down load the items.  You can create a workspace and do a get, or you can query the items and do a item.downloadfile().

    NetworkCredential networkCredential = new NetworkCredential("username", "password", "domain");
    ICredentials credential = (ICredentials)networkCredential;
    
    TeamFoundationServer server = new TeamFoundationServer("http://servername:8080", credential);
    VersionControlServer vcServer = (VersionControlServer)server.GetService(typeof(VersionControlServer));
    
    
  • Thursday, October 29, 2009 5:01 AMRuiz YiModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Waseem,

    As David mentioned, you can create a workspace or just download the files.

    Way1: Create a workspace and then get

            try
            {
                VersionControlServer.GetWorkspace(spacename, "usermane");
                VersionControlServer.DeleteWorkspace(spacename, "username");
            }
            catch { }
    
            Changeset changeset = VersionControlServer.GetChangeset(changesetID);
            Workspace ws = VersionControlServer.CreateWorkspace(spacename);
            ws.CreateMapping(new WorkingFolder("$/TFSProject1/",@"D:\workspace"));
            ws.Get(changeset.Changes.Select(c=>c.Item.ServerItem).ToArray(),  new ChangesetVersionSpec(changesetID),RecursionType.Full, GetOptions.None);
    
    

    Way2 Just DownLoad Files, but you need to create the path.
    Changeset changeset = TFSModal.Instance.VersionControlServer.GetChangeset(changesetID);
            foreach (var change in changeset.Changes)
            {
                change.Item.DownloadFile("path");
            }
    

    Best Regards,
    Ruiz
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Sincerely, Ruiz Yi