For the list of all the posts in this series please read this one
Context
If you ever need to produce a changelog for a release you could do it by hand, looking at all the work items associated with the changesets or you could use the TFS API to generate it automatically.
Required references
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.Common
Microsoft.TeamFoundation.VersionControl.Client
Microsoft.TeamFoundation.WorkItemTracking.Client
Query (C# Statements)
var branch = "$/Project1/Main"; var fromVersion = new ChangesetVersionSpec(1); var toVersion = VersionSpec.Latest; var tfs = TfsTeamProjectCollectionFactory .GetTeamProjectCollection(new Uri("http://localhost:8088/tfs")); tfs.EnsureAuthenticated(); var versionControl = tfs.GetService<VersionControlServer>(); var history = versionControl.QueryHistory(branch, VersionSpec.Latest, 0, RecursionType.Full, null, fromVersion, toVersion, int.MaxValue, false, false, false); history.OfType<Changeset>() .Select(x => new { x.ChangesetId, x.CreationDate, x.Committer, x.Comment, WorkItems = x.WorkItems.Select(wi => new { wi.Id, wi.Title, wi.Description, wi.State, wi.Reason }) }) .Dump("Branch history of: " + branch + " from " + fromVersion.DisplayString + " to " + toVersion.DisplayString); history.OfType<Changeset>() .OrderBy(x => x.ChangesetId) .SelectMany(x => x.WorkItems) .Select(wi => string.Format("[{0}] {1} #{2} - {3}", wi.Reason, wi.Type.Name, wi.Id, wi.Title)) .Dump("Changelog of branch: " + branch + " from " + fromVersion.DisplayString + " to " + toVersion.DisplayString);
Result
With this we will get the list of all the changesets and associated work items from the history of the given branch.
Branch history of: $/Project1/Main from C1 to T | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Changelog of branch: $/Project1/Main from C1 to T | |||
---|---|---|---|
|
2 comments:
Thanks man - this really helped me out. I added merged items and posted it here: https://gist.github.com/mika76/d2b6defbf20d7cfc7800
thanks this is really neat. i'm surprised TFS doesn't make info like this readily available anywhere
Post a Comment