Detecting the Team Project Collection in Team Foundation Server 2010 - tfs

I'm using the Team Foundation Server API to try to connect to a remote server.
From within my application, I try to connect to a URL of the form https://some-tfs-location.example.com/tfs but when doing so I get an error TF50309 (discussed here). If I add the project collection to the end of the URL (so the path becomes tfs/101) then I can connect with no problems.
I'd like to try and mimic the behaviour of Visual Studio, where I can give it a URL without needing to specify the project collection and it'll connect and locate the project collection.
Does anyone have any suggestions which API's I can use to mimic the Visual Studio behaviour? I had hoped to find the project collection via
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(projectRoot.ServerUrl,new MyCredentials());
var projectCollection = ttpc.CatalogNode.FullPath;
But this results in the same TF50309 error code.

You can use the TfsConfigurationServer class with the server Uri that has no team project collection (e.g. http://localhost:8080/tfs), get the ITeamProjectCollectionService service, and use GetCollections method or GetDefaultCollection method to retrieve the collection you want.
This blog post described it in more details.

Related

TF30063: You are not authorized to access IP

I am using below code to connect my tfs where executing machine is part of domain.
But when I try the same code in different machine (not in domain, but part of work group) getting unauthorized access error.
But in the same machine (where getting error), I am able to connect TFS with same account used in code via visual studio.
var tfsServer = new TfsConfigurationServer(
new Uri(ConfigurationManager.AppSettings["TFS_URI"]),
new NetworkCredential(
ConfigurationManager.AppSettings["TFSUserName"],
ConfigurationManager.AppSettings["TFSPassword"],
ConfigurationManager.AppSettings["Domain"]));
It's going to depend on getting the network credential specified properly. I'd suggest using Fiddler to take a look at what VS is sending and what your code is sending.

TeamCity can't connect to TFS

I'm trying to set up a TFS VCS root in TeamCity and I'm getting TF30063: You are not authorized to access http://tfsserver.com:8080/tfs. I know that the account that I'm using has access to the TFS server because it's the same one I use for Visual Studio and it works fine.
I checked the logs and they say that the request is returning a 500 error. For not authorized I would have expected a 401. Has anybody seen something like this before?
I don't do much with Team City but I would expect that it wants a URL to either a Collection or Team Project (which is not what the URL in your question is).
http://tfsserver.com:8080/tfs/DefaultCollection
or
http://tfsserver.com:8080/tfs/DefaultCollection/MyProject

How to map a TFS item url to something viewable

We are programmatically generating deployment emails, based on the history of changesets and associated workitems since the last deployed build. They look a bit like the build summary info inside Visual Studio (but with many builds combined).
There appear to be useful URLs in the data (like vstfs:///VersionControl/Changeset/205151), but being new to the TFS SDK I do not if/how this maps to a viewable item (e.g. http://tfsserver:port/somepath/...). The build summary links inside Visual Studio are clickable, but are they VS-only links?
If possible we want to include links in the email that open the related item (in a browser?), so I guess I need to know if TFS paths are web-browsable and if so, how?
Suggestions welcomed. Thanks.
This is the uRl i have been using to access work items,
=> http://ServerName:PortNumber/tfs/web/wi.aspx?id=xxidxx
Edit
The format i have specified does work with TFS 2010. It basically generates the path to the work item in Web view. Clicking on this opens the work item in the web view.
As an alternate, you could get a navigatable URL programmatically as well.
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFSURL"));
var versionControl = tfs.GetService<ICommonStructureService>();
var projects = versionControl.ListAllProjects();
var myService = tfs.GetService<TswaClientHyperlinkService>();
var myUrl = myService.GetChangesetDetailsUrl(21);
So, the service "TswaClientHyperlinkService" is microsofts TFS hyperlink service. This will generate the url formats for Absolute path, relative path, Path and Query, blah blah.
HTH,
Cheers, Tarun
PS - I hate to be wrong!!! hahaha...
EDIT
And since in your case you have the URI available and you already are using the TFS API, these two lines of code would do the trick.
var testManagementService = tfs.GetService<ILinking>();
var testControllers = testManagementService.GetArtifactUrl(#"vstfs:///VersionControl/Changeset/205151");
This will generate, https://ServerName:PortNumber/defaultcollection/VersionControl/Changeset.aspx?artifactMoniker=205151
HTH,
Cheers, Tarun
The following seems to be the standard url for accessing work items
http://TFS_Name:port_number/WorkItemTracking/Workitem.aspx?artifactMoniker=work_Item_Id
The vstfs links are called "artifact IDs" and are internal data to TFS that is expected to only be consumed by a TFS client. A TFS client will parse that data and determine how to display that data. For a changeset link like you provide, the rich clients will open up a dialog with the changeset details. A web client would translate that link into a URI. And the various TFS libraries are able to provide you more data on this artifact using that ID.
If you wanted to create your own link to TFS Web Access, the strictly proper way to do this is to query some information on the server. Once you have a TswaClientHyperlinkService, you can query for the Web Access URIs for various services, such as view a changeset or view a work item. Some examples are shown on Martin Woodward's blog.
In TFS2012, an additional pcguid URL parameter needs to be present. Here's the new format, extending the good solution given by #TarunArora:
http://ServerName:PortNumber/tfs/web/wi.aspx?pcguid=xxguidxx&id=xxidxx
This blog post describes how to find the pcguid via Visual Studio.
However, if like me you're attempting to use TFS without Visual Studio installed (don't ask!), here's an alternative using the browser-based TFS interface:
Go to "Open Issues"
Click on the button that looks like an envelope ("Send query as an email") in the top right of the work item pane.
Right-click on one of the links in the email and copy the link location
Cancel out of the email without sending it.
Paste link location into a text editor and extract the pcguid value.

Error deleting project in TFS

I created a "Test" project that I want to delete, using the following command:
TfsDeleteProject /server:xyz\sqlserver2008 “Test“
Getting this error:
TF30076: The server name or Uniform Resource Identifier (URI) you typed,
xyz\sqlserver2008, cannot be
resolved to a Team Foundation server.
If you type a server name, it must match the name you typed in the
Add Team Foundation Server dialog. If you type a URI, it must use
the following syntax: http[s]://:
The server instance is valid. (The installation of TFS is app tier and db are on seperate boxes) What might be going on ?
xyz is eht server name, sqlserver2008 is the db instance. For eg. I access the db using sql server management studio client app using xyz\sqlserver2008 as dbname.
Specify the full server URI including the http:// and :port. Also look for these error numbers in the MSDN.
Edit: Follow the first link, Andrew posted that's where I got my info from :)

TFS cannot retrieve the list of team projects

When I trying to access to list of my project from TFS, the error message as following prompting out
TF31001: Team Foundation cannot retrieve the list of team projects from Team Foundation Server 10.0.80.50. The Team Foundation Server returned the following error: Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section..
Does anyone facing this problem before and how do you solve it?
Thanks in advance
I got the same error out of sudden. Spent some time with my colleagues playing with different ways of launching Visual Studio 2008 and its configuration settings. I have found a couple of ways to bypass this error, although still don’t know what the original cause is. 1) Start VS with command line like this: devenv.exe /resetaddin. 2) Comment out the system.net setting within the devenv.exe.config. Like this:
<system.net>
<!-- <settings>
<ipv6 enabled="true"/>
</settings>
-->
</system.net>
They both work. I found the second option is more continent. Without this ipv6 setting I am not sure what else may be affected. But, at least I can make an emergency connection to my TFS server to check-in some files.
Team Explorer connects via web service to TFS. It sounds like you have a config issue with the proxy settings in IE that is preventing you from connecting to your server.
Try navigating to one of the web services directly using IE (e.g. http://yourtfsservername:8080/Services/v1.0/ServerStatus.asmx) and see if you get an error. If so, check your proxy settings - if they look OK, see if you can exclude the TFS server from being accessed via the proxy and go direct instead.
John Cheng's answer was so helpful. I changed the devenv.exe.config file like he mentioned and was able to connect to TFS. Before that, I had even tried re-installing Team Explorer to no benefit.

Resources