This article will help when you want to copy an existing Build definition from Project A to Project B.As shown in the following figure:The following is the piece of code to perform the task to copy a Build Definition from one project to another project.
using System;using System.Collections.Generic;using System.Linq;using System.Text;//Add this NameSpace to work on TFS apiusing Microsoft.TeamFoundation.Client;using Microsoft.TeamFoundation.Build.Client;//Author: Md. Jawed//Dated: 01.05.2010//Discription:Programmaticaly copy Build Definition from one project to another project using TFS API.namespace TFSAPI{ class Program { /// <summary> /// This Main would copy the Build definition from project "A" to Project "B" with in the same TFS. ///</summary> ///<param name="args"></param> staticvoid Main(string[] args) { try { //Connect to your TFS var server =TfsTeamProjectCollectionFactory.GetTeamProjectCollection(newUri("http://tfs:8080/tfs/defaultcollection")); IBuildServer buildServer = server.GetService<IBuildServer>(); //Get all Build from ALM project var buildDetails = buildServer.QueryBuildDefinitions("Project1"); foreach (var build in buildDetails) { if (build.Name=="DemoBuildDefinition") { var buildDefinition = buildServer.CreateBuildDefinition("Project2"); buildDefinition.Name = "Copy of " + build.Name; buildDefinition.BuildController = build.BuildController; // This finds the template to use buildDefinition.Process = buildServer.QueryProcessTemplates("Project2")[0]; buildDefinition.ProcessParameters = build.ProcessParameters; buildDefinition.Save(); }//end of if block }//end of for each loop }//end of try catch (Exception exception) { Console.WriteLine(exception.Message);
}//end of catch }//end of main }//end of class}//end of name space
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: