Search code examples
tfstfs-sdk

Programmatically delete a TFS branch


I want to programmatically delete a branch in TFS that was create automatically.

There is an existing method "ICommonStructureService.DeleteBranches" that should do the work. My problem is that the method requires a parameter "string[] nodeUris" that specifies the branch to delete using a "vstfs://... " URI and I just don't know how to get that for my branch.

What I need is something like:

var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri <myCollectionUrl>));
var cssService = projectCollection.GetService<ICommonStructureService3>();
var project = cssService.GetProjectFromName(<myProjectName>);

But how can I get the Branch Uri from there?


Solution

  • Meanwhile I found a solution. For deleting the branches I am using

    versionControl.Destroy(new ItemSpec(myBranchPath, RecursionType.Full), VersionSpec.Latest,  null, DestroyFlags.KeepHistory);
    

    This does exactly what I needed. versionControl is of type VersionControlServer and must be initialized using the Team Collection