简体   繁体   English

从TFS获取最新版本的文件

[英]Get latest version of file from TFS

I am trying to update local files from TFS but I can't get it to work. 我试图从TFS更新本地文件,但我无法让它工作。 I don't even know why it is failing because TFS doesn't throw me an exception or anything, it just silently defies me and doesn't update anything. 我甚至不知道为什么它会失败,因为TFS不会给我一个例外或任何东西,它只是默默地蔑视我并且不会更新任何东西。

public bool getLatest(string[] items)
{
    try
    {
        Workspace myWorkspace = createWorkspace();
        myWorkspace.Get(items, 
                        VersionSpec.Latest, 
                        RecursionType.Full, 
                        GetOptions.Overwrite);

        return true;
    }
    catch (Exception ex)
    {
        Tools.MessageLogger.LogError(ex.Message);
        return false;
    }
}

I have to add that all other communication with the TFS is just fine, pendingchanges, checkin or checkout are all working. 我必须补充一点,与TFS的所有其他通信都很好,等待更改,签入或结帐都可以。 This is quite frustrating. 这非常令人沮丧。

Whilst I've no prior knowledge in this, I thought I'd expand on my comment a little in the hope it might help (as no-one else seems to be answering). 虽然我之前没有这方面的知识,但我想我会稍微扩展我的评论,希望它可能有所帮助(因为似乎没有其他人回答)。

According to the documentation , WorkSpace.Get() should return a GetStatus object which tells you how many warnings/failures/conflicts there were - at the moment you're just throwing this information away. 根据文档WorkSpace.Get()应返回一个GetStatus对象,该对象告诉您有多少警告/失败/冲突 - 此时您只是抛弃了这些信息。

If you wanted to log the failures in getting latest in the same way that you're logging other errors, you could try this sort of thing: 如果您想以与记录其他错误相同的方式记录获取最新的失败,您可以尝试这样的事情:

public bool getLatest(string[] items)
{
    try
    {
        Workspace myWorkspace = createWorkspace();

        var results = myWorkspace.Get(items, VersionSpec.Latest, RecursionType.Full, GetOptions.Overwrite);
        var failures = results.GetFailures();

        foreach(var fail in failures)
        {
            Tools.MessageLogger.LogError(fail.GetFormattedMessage());
        }

        return failures.Count == 0;
    }
    catch (Exception ex)
    {
        Tools.MessageLogger.LogError(ex.Message);
        return false;
    }
}

I did write this in a text editor rather than a proper IDE, so apologies if I've made a typo/done something silly. 我确实在文本编辑器而不是正确的IDE中写了这个,所以如果我做了一个错字/做了一些愚蠢的事情,那就道歉了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM