代码之家  ›  专栏  ›  技术社区  ›  argatxa

如何使用c#API移动TFS文件?

  •  10
  • argatxa  · 技术社区  · 16 年前

    我真的找不到任何有关在TFS中以编程方式移动文件的参考资料。。。(命令行旁边)

    有人知道一个很好的指南/msdn起点,可以通过c#学习TFS源代码管理文件操作吗?

    2 回复  |  直到 10 年前
        1
  •  11
  •   TcKs    16 年前

    很简单:)。

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

    那你当然需要登记。“使用”workspace.GetPendingChanges文件()“和”工作区.签入()“方法。

        2
  •  7
  •   Jason Diller    16 年前

    下面是一个快速而肮脏的代码示例,它应该可以帮助您完成大部分工作。

    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; 
            }
        }
    }