2008-09-29 3 views
9

TFS API를 사용하여 C#으로 파일을 이동하는 방법에 대해 좋은 시간을 보내고 있습니다. 아이디어는 개발자가 데이터베이스 업그레이드 스크립트를 삭제하고 폴더에 빌드 프로세스를 가져 오는 폴더를 만들어서 빌드 스크립트를 만들고 폴더의 모든 파일을 방금 만든 데이터베이스 빌드 버전이있는 새 폴더로 이동하는 것입니다.C# API를 사용하여 TFS 파일을 어떻게 이동합니까?

내가 심각 통해 TFS 소스 제어 파일 조작을 학습을위한 사람이 좋은 가이드/MSDN의 시작점을 알고 있나요

(cmd 명령 라인의 옆) ... TFS에서 프로그래밍 방식으로 파일을 이동에 대한 참조를 찾을 수 없습니다

기음#?

답변

10

매우 간단합니다. :).

Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace = GetMyTfsWorkspace(); 
workspace.PendRename(oldPath, newPath); 

그런 다음 CheckIn해야합니다. "workspace.GetPendingChanges()"및 "workspace.CheckIn()"메서드를 사용하십시오.

7

여기에있는 대부분의 방법을 사용하는 빠르고 간단한 코드 샘플이 있습니다.

using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.VersionControl.Client; 


public void MoveFile(string tfsServer, string oldPath, string newPath) 
{ 
    TeamFoundationServer server = TeamFoundationServerFactory.GetServer(tfsServer, new UICredentialsProvider()); 
    server.EnsureAuthenticated(); 
    VersionControlServer vcserver = server.GetService(typeof(VersionControlServer); 
    string currentUserName = server.AuthenticatedUserName; 
    string currentComputerName = Environment.MachineName; 
    Workspace[] wss = vcserver.QueryWorkspaces(null, currentUserName, currentComputerName); 
    foreach (Workspace ws in wss) 
    { 

     foreach (WorkingFolder wf in wfs) 
     { 
      bool bFound = false; 
      if (wf.LocalItem != null) 
      { 
       if (oldPath.StartsWith(wf.LocalItem)) 
       { 
        bFound = true; 
        ws.PendRename(oldPath, newPath); 
        break; 
       } 
      } 
      if (bFound) 
       break; 
     } 
    } 
} 
관련 문제