0

Been looking all day for a solution for this, with little to no luck. I have this Windows Forms app in C# - My goal is to branch a directory that is in my TFS repository, make changes to filenames/folder names within the newly created branch if possible, and check code back into TFS with updated folder name/filename structure.

Is there a package or a class that I'm not seeing that would allow me to create and manipulate branches, as well as checking in the code all from a c# winforms app? If so, an example would be much appreciated.

dlimes
  • 95
  • 2
  • 10
  • You could use the command line tool [tf](https://learn.microsoft.com/en-us/vsts/tfvc/use-team-foundation-version-control-commands). Or the [Microsoft.TeamFoundation.Client](https://msdn.microsoft.com/en-us/library/bb286958%28v=vs.120%29.aspx?f=255&MSPPError=-2147217396) – Yuriy Faktorovich Mar 09 '18 at 16:50
  • [How to create a new source code branch using TFS API](https://stackoverflow.com/questions/1559180/how-to-create-a-new-source-code-branch-using-tfs-api) – stuartd Mar 09 '18 at 17:23
  • [Check-in code into TFS Server by using TFS API](https://stackoverflow.com/questions/20487590/check-in-code-into-tfs-server-by-using-tfs-api) – stuartd Mar 09 '18 at 17:24

1 Answers1

1

If you are using Client Object Model Reference to manage the Version Control programmatically.

To create a branch, you need to use the "CreateBranch()" method in Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer class.

Creates a branch on the server and checks it in without downloading the branch to the client.

A sample for you reference:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;
using System.Net;

namespace Model.versionControl
{
    public static class CreateBranch
    {

            public static void CreateBranchWithComment()
            {
                NetworkCredential cre = new NetworkCredential("userName", "password", "domain");
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://TFSServerName:8080/tfs/CollectionName"), cre);
                VersionControlServer vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
                int changesetId = vcServer.CreateBranch(@"$/SourceControl/WebSites", "$/SourceControl/WebSites_Branch", VersionSpec.Latest);
                new WorkspaceVersionSpec("machineName","domain\userName");
                Changeset changeset = vcServer.GetChangeset(changesetId);

                changeset.Update();

    }

    }
}

You could also take a look at this similar question: How to create a new source code branch using TFS API?

As for renaming a file or directory, you could use Workspace.PendRename Method, sample code please refer: How do I move a TFS file with c# API?

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62