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

arg*_*txa 10 c# api tfs

我一直在谷歌搜索如何使用TFS API使用c#移动文件.我们的想法是拥有一个文件夹,开发人员可以在其中删除数据库升级脚本,并且构建过程到文件夹创建构建脚本,并将文件夹上的所有文件移动到我们刚创建的数据库构建版本的新文件夹.

我无法认真地找到关于在TFS中以编程方式移动文件的任何参考...(除了cmd命令行)

有没有人知道通过c#学习TFS源控制文件操作的良好指南/ msdn起点?

TcK*_*cKs 11

它非常简单:).

Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace = GetMyTfsWorkspace();
workspace.PendRename( oldPath, newPath );
Run Code Online (Sandbox Code Playgroud)

然后你需要CheckIn它当然.使用"workspace.GetPendingChanges()"和"workspace.CheckIn()"方法来执行此操作.


Jas*_*ler 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; 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)