简体   繁体   中英

How to Programatically get TFS Team Project Name

I am creating a check-in policy using:

using Microsoft.TeamFoundation.VersionControl.Client;

I want to get the current TFS Team Project Name from the current workspace or the PendingCheckin

Any ideas?

You can use VersionControlServer.GetTeamProjectForServerPath on a pending change thus:

var pendingChange = pendingCheckin.GetAllPendingChanges().FirstOrDefault();
if(pendingChange != null) {
    return vcs.GetTeamProjectForServerPath(pendingChange.ServerItem);
}

This also means you can detect if pending changes span multiple team projects.


Edit/expansion:

Now that I think about it, you should probably use the local path, since the files you're checking in might not be on the server yet (adds).

So you can use Workspace.GetTeamProjectForLocalPath instead:

var workspace = pendingCheckin.GetWorkspace();
var pendingChange = pendingCheckin.GetAllPendingChanges().FirstOrDefault();
if(pendingChange != null) {
    return workspace.GetTeamProjectForLocalPath(pendingChange.LocalItem);
}

You can access it with

  BuildDetail.TeamProject

Find the assembly in: C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\ReferenceAssemblies\\v2.0\\Microsoft.TeamFoundation.Build.Client.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM