I have updated TFS check-in policy for StyleCop 4.3.3.0 and also compiled a version for TFS 2010 (now that it has RTM’ed).
The sources and MSIs (one for TFS 2008 and one for TFS 2010) are now available at MSDN Code Gallery.
Enjoy!
I have updated TFS check-in policy for StyleCop 4.3.3.0 and also compiled a version for TFS 2010 (now that it has RTM’ed).
The sources and MSIs (one for TFS 2008 and one for TFS 2010) are now available at MSDN Code Gallery.
Enjoy!
Can you connect to TFS 2010 server using 2008 client? Sure you can! There are couple of gotchas to be aware of, specifically you’d be better off installing an update for TFS 2008; if you do not the following message comes up:
Grant Holliday wrote very detailed post on what needs to be installed and what to do if for some reason you cannot install the update.
However, I wanted to mention this in context of custom tools that use object model. While connecting to TFS 2010 with Team Explorer 2008 will produce the message above (and will require extra steps such as update installation to get TE working), the message won’t appear for your custom tools. In fact, if the connection to TFS 2010 is defined in registry you will connect and may not know the difference from inside of your tool.
Thus if you have custom tools using 2008 OM connecting to TFS 2010, it is your responsibility that the update gets installed correctly on machines with the tools.
When you login to TFS using object model, sometimes it may be useful to get information about logged in user (such as domain, account, email etc.).
In TFS 2008 object model, one would get the logged in user display name, domain name, account name and email as following:
1 TeamFoundationServer server = new TeamFoundationServer("tfsserver",
2 new System.Net.NetworkCredential("domain_name\\user_name", "pwd"));
3 server.EnsureAuthenticated();
4
5 Console.Write(server.AuthenticatedUserDisplayName);
6 // returns user's display name
7
8 Console.Write(server.AuthenticatedUserName);
9 // returns domain_name\user_name
10
11 // AuthenticatedUserIdentity is Microsoft.TeamFoundation.Server.Identity
12 Console.Write(server.AuthenticatedUserIdentity.Domain + "\\" +
13 server.AuthenticatedUserIdentity.AccountName);
14 // returns domain_name\user_name
15
16 Console.Write(server.AuthenticatedUserIdentity.MailAddress);
17 // returns user’s email
In TFS 2010 OM, AuthenticatedUserDisplayName, AuthenticatedUserName and AuthenticatedUserIdentity properties are all deprecated, and instead AuthorizedIdentity property is introduced on Team Project Collection class. The code below makes use of the new property to retrieve logged in user information:
1 TfsTeamProjectCollection collection = new TfsTeamProjectCollection(
2 new Uri(http://tfsserver:8080/tfs/defaultcollection,
3 new System.Net.NetworkCredential("domain_name\\user_name", "pwd"));
4 collection.EnsureAuthenticated();
5
6 // AuthorizedIdentity is Microsoft.TeamFoundation.Framework.Client.TeamFoundationIdentity
7 Console.Write(collection.AuthorizedIdentity.DisplayName);
8 // returns user's display name
9
10 Console.Write(collection.AuthorizedIdentity.GetAttribute("Domain", "default"));
11 // returns domain_name
12
13 Console.Write(collection.AuthorizedIdentity.GetAttribute("Account", "default"));
14 // returns user_name
15
16 Console.Write(collection.AuthorizedIdentity.GetAttribute("Mail", "default"));
17 // returns user’s email
When starting up with TFS 2010 object model, there are few gotchas to be aware of (especially if you did coding for TFS OM 2005/2008 in the past). See my previous post for high-level details:
In 2008 one would establish connection to TFS as follows
1 string[] servers = RegisteredServers.GetServerNames();
2
3 // select one of the servers (in real life combo box?)
4 string serverName = servers[0];
5
6 TeamFoundationServer server = new TeamFoundationServer(serverName,
7 new System.Net.NetworkCredential(userName, password));
8
9 server.EnsureAuthenticated();
In Team Foundation Server 2010 the code becomes:
1 RegisteredTfsCollection[] projects = RegisteredTfsConnections.GetProjectCollections();
2 List<string> servers = new List<string>();
3 foreach (RegisteredTfsCollection collection in collections)
4 {
5 if (!collection.Offline)
6 results.Add(collection.Uri.ToString());
7 }
8
9 // select one of the servers (in real life combo box?)
10 string serverName = servers[0];
11
12 TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri(tfsServerName),
13 new System.Net.NetworkCredential(userName, password));
14
15 server.EnsureAuthenticated();
Should be no big surprises considering the changes in 2010 – one server w\projects became multiple projects collections. One thing to be aware of is the change in the arguments you pass to constructor of TfsTeamProjectCollection; in 2005/2008 one was able to pass server name (i.e. “tfserver”) as retrieved by using RegisteredServers class. In 2010 that becomes impossible since the server may contain multiple collections; thus you have to pass full URI (e.g. “http://tfsserver:8080/tfs/DefaultCollection”).