42

TFS 2010 を使用してソース管理下にあるファイルを処理するユーティリティに取り組んでいます。

アイテムがまだ編集のためにチェックアウトされていない場合、ファイルが読み取り専用モードであるため、間違いなく予測可能な例外が発生します。

ファイルをチェックアウトするにはどのような方法がありますか?

Process.Start("tf.exe", "...");PS私は、それが該当する場合ではなく、プログラマティックのために何かが欲しい.

4

6 に答える 6

40

Some of the other approaches mentioned here only work for certain versions of TFS or make use of obsolete methods. If you are receiving a 404, the approach you are using is probably not compatible with your server version.

This approach works on 2005, 2008, and 2010. I don't use TFS any longer, so I haven't tested 2013.

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
using (var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri))
{
    var workspace = workspaceInfo.GetWorkspace(server);    
    workspace.PendEdit(fileName);
}
于 2012-02-23T16:59:31.327 に答える
6
private const string tfsServer = @"http://tfsserver.org:8080/tfs";

public void CheckOutFromTFS(string fileName)
{
    using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)))        
    {
        if (pc != null)
        {
            WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
            if (null != workspaceInfo)
            {                   
                Workspace workspace = workspaceInfo.GetWorkspace(pc);
                workspace.PendEdit(fileName);
            }
        }
    }
    FileInfo fi = new FileInfo(fileName);
}

廃止されたことに注意してくださいMicrosoft.TeamFoundation.Client.TeamFoundationServerFactoryTeamFoundationServerクラスは廃止されました。TeamFoundationProjectCollectionまたはクラスを使用しTfsConfigurationServerて、2010 TeamFoundationServerと通信します。2005または2008のTeamFoundationServerと通信するには、TeamFoundationProjectCollectionクラスを使用します。これに対応するファクトリクラスはですTfsTeamProjectCollectionFactory

于 2012-11-26T11:01:10.400 に答える
4

Team Foundation バージョン管理クライアント API を使用できます。メソッドはPendEdit()

workspace.PendEdit(fileName);

MSDN http://blogs.msdn.com/b/buckh/archive/2006/03/15/552288.aspxで詳細な例を確認してください。

于 2011-02-23T22:27:47.287 に答える
2

最初にワークスペースを取得します

var tfs = new TeamFoundationServer("http://server:8080/tfs/collection");
var version = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
var workspace = version.GetWorkspace("WORKSPACE-NAME", version.AuthorizedUser);

ワークスペースを使用すると、ファイルをチェックアウトできます

workspace.PendEdit(fileName);
于 2011-06-27T13:29:36.187 に答える
1
var registerdCollection = RegisteredTfsConnections.GetProjectCollections().First();
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(registerdCollection);
var versionControl = projectCollection.GetService<VersionControlServer>();

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(_fileName);
var server = new TeamFoundationServer(workspaceInfo.ServerUri.ToString());
var workspace = workspaceInfo.GetWorkspace(server);

workspace.PendEdit(fileName);
于 2011-06-27T13:38:42.017 に答える
0

それを行う方法には、単純なものと高度なものの 2 つの方法があります。

1)。単純:

  #region Check Out
    public bool CheckOut(string path)
    {
        using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConstTfsServerUri)))
        {
            if (pc == null) return false;

            WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(path);
            Workspace workspace = workspaceInfo?.GetWorkspace(pc);
            return workspace?.PendEdit(path, RecursionType.Full) == 1;
        }
    }

    public async Task<bool> CheckoutAsync(string path)
    {
        return await Task.Run(() => CheckOut(path));
    }
    #endregion

2)。アドバンスト (受信ステータスあり):

    private static string GetOwnerDisplayName(PendingSet[] pending)
    {
        var result = pending.FirstOrDefault(pendingSet => pendingSet.Computer != Environment.MachineName) ?? pending[0];
        return result.OwnerDisplayName;
    }
    private string CheckoutFileInternal(string[] wsFiles, string folder = null)
    {
        try
        {

            var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(folder);
            var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
            var workspace = workspaceInfo.GetWorkspace(server);
            var request = new GetRequest(folder, RecursionType.Full, VersionSpec.Latest);
            GetStatus status = workspace.Get(request, GetOptions.None);
            int result = workspace.PendEdit(wsFiles, RecursionType.Full, null, LockLevel.None);
            if (result == wsFiles.Length)
            {
                //TODO: write info (succeed) to log here - messageText
                return null;
            }
            var pending = server.GetService<VersionControlServer>().QueryPendingSets(wsFiles, RecursionType.None, null, null);
            var messageText = "Failed to checkout !.";
            if (pending.Any())
            {
                messageText = string.Format("{0}\nFile is locked by {1}", messageText, GetOwnerDisplayName(pending));
            }

            //TODO: write error to log here - messageText
            return messageText;
        }
        catch (Exception ex)
        {
            UIHelper.Instance.RunOnUiThread(() =>
            {
                MessageBox.Show(Application.Current.MainWindow, string.Format("Failed checking out TFS files : {0}", ex.Message), "Check-out from TFS",
                               MessageBoxButton.OK, MessageBoxImage.Error);
            });
            return null;
        }
    }

    public async Task<string> CheckoutFileInternalAsync(string[] wsFiles, string folder)
    {
        return await Task.Run(() => CheckoutFileInternal(wsFiles, folder));
    }
于 2016-07-04T15:19:11.213 に答える