Friday, April 11, 2008

How to get the BuildNumber from TFS

I’ve spent close to a week figuring out how to do this.
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)

ScriptManager in UserControl

I added a Script Manager in a user control and got the following error message: “Only one instance of a ScriptManager can be added to the page.”
The issue is the parent page (either the aspx page or master page) has a scriptmanager.
Now comes another part I added the UpdatePanel but I found out that when I wanted a partial refresh Page_Load event is getting fired!!
This could be b’coz the way this Control is called in the aspx page!!
Even if you do AJAX if the aspx calls the control in page load event we will not be able to help it out.
Bottomline: Think twice before adding AJAX in usercontrol.

Sunday, April 6, 2008

MSWord Uppercase - Lowercase

Highlight the passage and then press shift F3