Skip to content

Instantly share code, notes, and snippets.

@kiyokura
Created September 4, 2012 02:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyokura/3615744 to your computer and use it in GitHub Desktop.
Save kiyokura/3615744 to your computer and use it in GitHub Desktop.
TFSのAPIを使って、ソースコードの最新をローカルに取得するサンプ
// TFSのAPIを使って、ソースコードの最新をローカルに取得するサンプル
// 参考:
// MSDN
// http://msdn.microsoft.com/ja-jp/library/microsoft.teamfoundation.versioncontrol.client.workspace%28v=vs.100%29.aspx
// StacK Overflow
// http://stackoverflow.com/questions/8341419/get-latest-using-tfs-api
// http://stackoverflow.com/questions/1827651/how-do-you-get-the-latest-version-of-source-code-using-the-team-foundation-serve
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var teamCollectionUrl = @"http://myTfsServer:8080/tfs/MyTeamCollection";
var projectSourcePath = @"$/HogeApps";
// var workSpaceName = "MyWorkSpace";
// var workSpaceOwnerName = "OwnerName";
// // workSpaceNameとworkSpaceOwnerNameはそれぞれ、
// // Visual Studioのメニューの[ファイル]-[ソース管理]-[ワークスペース]の
// // [名前]カラムと[所有者]カラムの値を指定
var localMapPath = @"C:\MyTfs\MyTeamCollection";
// ワークスペースをマップしているローカルパスを指定しても良さそう
var tpc = new TfsTeamProjectCollection(new Uri(teamCollectionUrl),
new UICredentialsProvider());
tpc.EnsureAuthenticated();
var vcServer = tpc.GetService<VersionControlServer>();
//var myWorkspace = vcServer.GetWorkspace(workSpaceName, workSpaceOwnerName);
var myWorkspace = vcServer.GetWorkspace(localMapPath);
// マップしているローカルパスを使ってワークスペースを指定するならGetWorkspace(localMapPath)を利用。
// ワークススペース名とオーナー名を指定しるなら.GetWorkspace(workSpaceName, workSpaceOwnerName)
var request = new GetRequest(new ItemSpec( projectSourcePath, RecursionType.Full), VersionSpec.Latest);
myWorkspace.Get(request, GetOptions.Overwrite | GetOptions.GetAll);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment