Export TFS 2010 History to Excel or Text Document - tfs

How do you export history from TFS 2010 that includes the user, date and the complete comment (not truncated)?
For example, in Team Explorer: right-click team member name > show check-in history. This will bring up the user's check-in history, but the comments are truncated.

You have 3 options here:
Parse output from the tf.exe history command.
Write code against the TFS client object model.
Write a query directly against the TFS database.
Number 1 is probably the easiest so I'll start with that. You can read the documentation for the tf history command here. In order to get the comment non-truncated you will need to use the /format:detailed option. If you want all of the history, try something like this:
tf history $/ /r /format:detailed /noprompt
If you are looking for all of the changesets for a given user, try this:
tf history $/ /r /format:detailed /user: /noprompt
That will produce a fair amount of text output that you would need to parse to be able to put it into excel. Give that a shot and if you are interested in options 2 or 3 let me know and I can give you more details.

The easiest way is to connect to the TFSWharehouse from excel, then pull the data from the source control history in a excel sheet. This is really simple and very powerful.
You'll find useful info here: http://www.woodwardweb.com/vsts/getting_started.html
Edit:
Using the TFS API to enumerate the changesets when you don't have access to SSAS (e.g. tfspreview.com for instance):
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, true);
tpp.ShowDialog();
var tpc = tpp.SelectedTeamProjectCollection;
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
var tp = versionControl.GetTeamProject("MyTeamProject");
var path = tp.ServerItem;
var q = versionControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, null, new ChangesetVersionSpec(1), VersionSpec.Latest, Int32.MaxValue, false, true, false, false);
foreach (Changeset cs in q)
{
var user = cs.Owner;
var comment = cs.Comment;
var date = cs.CreationDate;
Debug.WriteLine(string.Format("[{3}] Date: {0}, User: {1}, Comment {2}", date, user, comment, cs.ChangesetId));
}

You can also use TFS Rest API like this:-
https://{accountName}.visualstudio.com/{project}/_apis/tfvc/changesets?
searchCriteria.author={userName}&$top=100
This will generate a JSON, you can upload it to any online site like https://json-csv.com/ and get the CSV.

A simpler rendition than the above for visualstudio.com
https://{accountName}.visualstudio.com/{project}/_apis/tfvc/changesets?$top=10000&maxCommentLength=2000
You need the max comment length to stop it from truncating.
The above tool didn't work, but this one does: http://www.convertcsv.com/json-to-csv.htm

This is really not an automated export however,thought of sharing.
For VS2015 What I found easier was following(around 20 changesets)
Opened the branch in VS2015
Right Click=>View History=>All changesets Visible
Clicked on each changeset ==>Right Click=>Changeset Details
Team Explorer-Changeset Details Opens on Right.
Select one of the file.
Using Shift and Down arrow you can copy the entire list of files in that particular changeset.
Paste to an Excel Sheet(it copied the path of files with the file names)
Did above for all the changesets and got my complete list.

Related

Find XML file changes in all branches

I have an XML file in my main TFS branch. I have 50 branches of the main folder. Is there a quick way to check in which branches the file is modified before merging it to the main branch?
I have found that it can be done with CodeLens for code files, but I don't know how to do it for XML files.
You can refer to these steps below:
Create a new workspace
Map these branches (Do not include other mapping)
To do work (e.g. modify files)
Open Team Explorer
Switch to this workspace
Click Pending Changes, then all changes in this workspace will be list.
If these changes are already existing in different workspace, you can check in changes through TFS API (install Microsoft Team Foundation Server Extended Client package to your project).
Simple code to iterate all workspaces in a machine and check in specified changes:
NetworkCredential cred = new NetworkCredential("[username]", "[password]", "[domain]");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("[collection url"), cred);
tpc.EnsureAuthenticated();
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
var spaces = versionControl.QueryWorkspaces(null, null, "[machine name, can be null]");
foreach(var currentWorkspace in spaces)
{
var libChanges= currentWorkspace.GetPendingChanges("[server or local path]",RecursionType.Full);
if (libChanges.Count() > 0)
{
currentWorkspace.CheckIn(changes: libChanges, comment: "checkInAPI");
}
}
Update:
You can compare branches.
Open Source Control Explorer
Right click a branch > Compare
Change Target path to target branch server path
Click OK.
On the other hand, there is an TFS Productivity Pack extension you can use.

Plastic SCM external diff on Mac

I am attempting to set up Araxis diff as my external diff tool on Mac.
Command Line Reference:
http://www.araxis.com/merge_mac/command_line.html
I have set up a diff tool in the Diff Tool Configuration in the Preferences panel of Plastic with the following settings:
External Diff Tool ( selected )
Path: /usr/local/bin/compare -wait #sourcesfile #destinationfile
Use this tool for text files ( selected )
I have also attempted setting specific extensions and removing all other diff tools to no avail.
The internal diff tool shows up regardless of the settings.
Please advise what would be my next steps.
You have to use the priority arrows to set your new diff and merge tool in the first position. If a diff or merge tool is on top with no file type restriction that is the one that is going to be used, make sure your new Araxis merge tool is on top.
In order to configure the diff tool with more details I do recommend you to use the following configuration:
"/usr/local/bin/compare" /wait /2 /title1:"#sourcesymbolic" /title2:"#destinationsymbolic" #sourcefile #destinationfile
And for the merge tool you can use the following one:
"/usr/local/bin/compare" /wait /a3 /3 /title1:"#sourcesymbolic" /title2:"Workspace version" /title3:"#basesymbolic" #sourcefile #destinationfile #basefile #output
You will have this new tool available for the merge and file diff. The branch, changeset... will remain the built-in one.

How can I create a directory in my source control using TFS 2010 SDK?

I want to customize the creation of a TFS project using TFS 2010 SDK.
I have already create a process template and use this sample, but I want to create a specific directory tree for the new team project base on a XML file which describe the tree. My problem is this message; The array must contain at least one element.
Parameter name: checkinParameters.PendingChanges
I initialize the TFS, map the server folder with a local folder and create directories in both.
fooString = Array.Find<WorkingFolder>(workspace.Folders, m => m.ServerItem.Contains("$/FR_DEV"));
Directory.CreateDirectory(ElementPath);
Directory.CreateDirectory(fooString.ServerItem + ElementTfsPath);
After that:
PendingChange[] PendingChanges = workspace.GetPendingChanges();
// Checkin the items we added
int changesetForAdd = workspace.CheckIn(PendingChanges, "Project creation.");
However, I get an error for the pending change! How can I fix this?
my problem was that i need to add the directory in the workspace not with a simple path
workspace.PendAdd(currentSubDirectory, true);

How to Move TFS 2010 Build Definition between Projects?

I have some TFS 2010 build definitions that were created under ProjectX. Now the source code has moved to a folder subordinate to ProjectY. How can I move the build definitions to ProjectY so they display under the Builds node of the Team Explorer for ProjectY?
I don't think there is something out of the box to copy the build definitions from one project to another. However you should be able to do it using the TFS API. You will want to move the build process templates, which is what Pete is referring to, into the Build Process Template folder for the new project. After that you would do something like:
var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<server uri>"));
IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Project X");
foreach(var build in buildDetails)
{
var buildDefinition = buildServer.CreateBuildDefinition("Project Y");
buildDefinition.Name = "Copy of " + build.Name;
buildDefinition.BuildController = build.BuildController;
// This finds the template to use
buildDefinition.Process = buildServer.QueryProcessTemplates("Project Y")[0];
buildDefinition.ProcessParameters = build.ProcessParameters;
buildDefinition.Save();
}
A couple of things to note. You will need deal with converting the workspace mappings from one project to the other. You will also need to change the buildDefinition.Process line to find the specific template.
A powershell version of Sean's answer above
# Copy some TFS build defintions from one project collection to another
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$tfsUrl = "http://lontfs_at:8080/tfs/XXX"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsUrl)
$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$buildServer = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDetails = $buildServer.QueryBuildDefinitions("Project X");
foreach( $build in $buildDetails)
{
$buildDefinition = $buildServer.CreateBuildDefinition("Project Y");
$buildDefinition.Name = "Copy of " + $build.Name;
$buildDefinition.BuildController = $build.BuildController;
# This finds the template to use
$buildDefinition.Process = $buildServer.QueryProcessTemplates("Project Y")[0];
$buildDefinition.ProcessParameters = $build.ProcessParameters;
$buildDefinition.Save();
}
In VS2010, the TFS Power Tools can move a build definition from one project to another as demonstrated in the 2nd answer in this link: Is it possible to Export TFS 2010 Build Definitions?, and as shown below.
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tfpt
builddefinition /collection:"http://ServerX:8080/tfs/Collection X" /clone "Project 1\Build
Definition X" "Project 2\Copy of Build Definition X"
The TFS Power Tools for VS2010 can be downloaded from: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f
Uggly but very efficient way to move (not to duplicate) only one or two Build Definitions:
Open SQL Server Management Studio,
Open your Collection DB
Edit the table tbl_BuildDefinition
Replace the current GroupId with the target Team Project's GroupId
That's it ;)
To determine the GroupId of the target Team Project, simply find any BuildDefinition of that Team Project in tbl_BuildDefinition and take its GroupId.
For sure, you have next to update the BuildDefinition's workspace, Items to build, ... to use the server path of the new Team Project !
If you get an error like "GroupItem cannot be move accross Team Project" when updating your BuildDefinition, it was most probably already open before updating the DB. Close and reopen it.
If you don't intend to repeat this operation too often, it's IMO the fastest solution.
V.
Build definitions are just another source controled file in TFS, you should be able to open the build definition in ProjectX and save it as a new file to projectY's build definitions folder.
Edit
In the above post I am assuming ProjectX and ProjectY are TFS projects, in which case their workflow build definition(s) are simply in the builddfinitions folder of their respective source control roots.
Sean's answer helped me out, but in my case, I have only one repository for my build templates and custom activities assemblies. So I don't need to edit settings, I just want to copy one build definition from TFS Project A to TFS Project B.
Here is my 'short' version of Sean's code:
var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS URL"));
IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Proj_A");
foreach(var build in buildDetails)
{
var buildDefinition = buildServer.CreateBuildDefinition("Proj_B");
buildDefinition.CopyFrom(build);
buildDefinition.Save();
}

How do you SetMaxAttachmentSize in TFS 2010?

I want to set the maximum work item attachment size. From old blogs I have found that it is possible by calling SetMaxAttachmentSize, but the blogs are for older versions of TFS. I have found the new webservice path for TFS 2010.
http://localhost:8080/tfs/_tfs_resources/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx/SetMaxAttachmentSize
Unfortunately when I call it like that I receive this error: This request can only be made against a project collection. The (.asmx) file should be located in the project directory (usually _tfs_resources under the application root).
I don't know how to format the call via a browser to target a specific project collection. Any thoughts?
Apparently SetMaxAttachmentSize web service was not leveraged on TFS 2010 therefore you need to do this programmatically, try running the following code:
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(#"http://yourtfsserver:8080/tfs/DefaultCollection");
ITeamFoundationRegistry rw = tfs.GetService<ITeamFoundationRegistry>();
RegistryEntryCollection rc = rw.ReadEntries(#"/Service/WorkItemTracking/Settings/MaxAttachmentSize");
RegistryEntry re = new RegistryEntry(#"/Service/WorkItemTracking/Settings/MaxAttachmentSize", "20971520"); //20MB
if (rc.Count != 0)
{
re = rc.First();
re.Value = "20971520";
}
rw.WriteEntries(new List<RegistryEntry>() { re });
I hope it works for you
Regards,
Randall Rosales
I have found that this works. It is easier than writing code.
Go to this url replacing <Collection> with your project collection: http://localhost:8080/tfs/<Collection>/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx
Choose SetMaxAttachmentSize
You can test to make sure you set it correctly by going to the same url above and then selecting GetMaxAttachmentSize.

Resources