如何移动TFS用C#API文件?(How do I move a TFS file with c#

2019-08-16 23:19发布

我一直在google搜索上如何移动一个文件使用TFS API C#的好时机。 这个想法是有其开发商降数据库升级脚本的文件夹,并生成过程中获得的文件夹创建一个构建脚本和文件夹中的所有文件移动到与我们刚刚创建的数据库建立版本的新文件夹。

我不能认真查找有关TFS编程移动文件的任何引用......(除了cmd命令行)

没有任何人知道一个很好的指南/ MSDN起点,通过C#学习TFS源控制文件操作的?

Answer 1:

它很简单:)。

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

然后,你需要签入,当然它。 使用“workspace.GetPendingChanges()”和“workspace.CheckIn()”方法来做到这一点。



Answer 2:

这里是一个应该让你最的方式有一个快速和肮脏的代码示例。

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


文章来源: How do I move a TFS file with c# API?
标签: c# api tfs