Blog Stats
  • Posts - 63
  • Articles - 0
  • Comments - 6
  • Trackbacks - 0

 

Simple TFS 2012 API Methods: List Projects in a Collection and Import WIT Definitions

I found a lot of code to do these things, but really appreciated a more concise and simple approach. For example, this can be run as a unit test.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
[TestMethod]
        public void ImportProcessTemplateWitDefinitionsToCollection()
        {
            string wsPath = @"{your path}\WorkItem Tracking\TypeDefinitions\";
            List<string> wits = new List<string>();
            wits.Add("Bug.xml");
            wits.Add("Task.xml");
            wits.Add("UserStory.xml");

            TfsTeamProjectCollection tpc = 
                new TfsTeamProjectCollection(new Uri("{your collection url}"))
            tpc.EnsureAuthenticated();
            var wis = new WorkItemStore(tpc);
            var projects = (from Project p in wis.Projects select p.Name).ToList();

            foreach (var targetTfsProjectName in projects)
            {
                foreach (string wit in wits)
                {
                    XmlDocument WitDefFile = new XmlDocument();
                    WitDefFile.Load(wsPath + wit);
                    string WitDef = WitDefFile.InnerXml;
                    wis.Projects[targetTfsProjectName].WorkItemTypes.Import(WitDef);
                }
            }
        }

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 
 

 

 

Copyright © Bob Hardister