I tried different options, the one which I spent a hell lot of time is to use $(BuildNumber). I thought I can create a custom Task using a C# dll which will grab the BuildNumber and update in web.config. I can easily display the info from web.config.
I don’t have rights to go in a TFS to run a build, so I was unable to progress much in this direction. Also we will never know whether we can update the web.config after its build and it’s a cumbersome process.
The next step then will be to somehow get the API to work in TFS.
In internet I was able to get some namespace but I was unable to locate these namespace in Reference under .NET.
I thought I was missing some APIs that I need to download but I had no idea where to go.
My colleague gave me a path to look at in my PC to get some TFS client dlls, I added them and got the namespace.
Once I got the namespace getting the methods to grab the BuildNumber was fairly easy.
Lemme explain the steps:
Grab the dll which is in C:\Program Files\Microsoft Visual Studio 8\Common7\ide\PrivateAssemblies as references look for dll starting with “Microsoft.TeamFoundation.<>”
Add Namespace
***************************
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Build.Proxy;
***************************
Here is the code to grab the BuildNumber
***************************
#region Get Build Number
TeamFoundationServer tfs = new TeamFoundationServer("
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
BuildStore bs = (BuildStore)tfs.GetService(typeof(BuildStore));
BuildData[] bt = bs.GetListOfBuilds (
lblBuildNum.Text = bt[bt.GetUpperBound(0)].BuildNumber;
tfs.Dispose();
#endregion
***************************
URL: In Visual Studio File à Add Existing Team Project. In “Connect to Team Foundation Server” click on Servers. Here you can get the URL
Project Name: Type your Team Project, the list of Team Projects are displayed in the “Connect to Team Foundation Server”
Build Type: In Team Explorer expand Team Builds take any one of the Build Types mentioned there. (Don’t enter “All Build Types” it will not work)