是否可以使用 TFS 2015 api 从 TFS 2010 查询历史变更集?

Is it possible to use TFS 2015 api to QueryHistory changesets from TFS 2010?

我正在使用 TFS API 将 TFS 2010 团队项目迁移到 TFS 2015。我在尝试调用 VersionControlServer.GetLatestChangesetId()VersionControlServer.QueryHistory(...) 时遇到了问题 运行。

我正在使用 2015 年的 nuget Team Foundation 包来提供 dll。

我遇到的异常是:

'VersionControlServer.GetLatestChangesetId()' threw an exception of type 'System.Xml.XmlException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146232000
    HelpLink: null
    InnerException: null
    LineNumber: 0
    LinePosition: 0
    Message: "Unexpected end of file."
    Source: "System.Runtime.Serialization"
    SourceUri: null
    StackTrace: "   at System.Xml.EncodingStreamWrapper.ReadBOMEncoding(Boolean notOutOfBand)\r\n   at System.Xml.EncodingStreamWrapper..ctor(Stream stream, Encoding encoding)\r\n   at System.Xml.XmlUTF8TextReader.SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsSoapMessageEncoder.ReadMessage(Stream stream)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.ReadMessage(HttpWebResponse webResponse, WebException webException, Stream responseStream, Boolean& closeResponse)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.ReadResponse(HttpWebResponse webResponse, WebException webException)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.IsAuthenticationChallenge(TfsMessage requestMessage, HttpWebResponse webResponse, WebException webException, TfsMessage& responseMessage)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendR
equest()\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpRequestChannel.Request(TfsMessage message, TimeSpan timeout)\r\n   at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)\r\n   at Microsoft.TeamFoundation.VersionControl.Client.Repository.GetRepositoryProperties()\r\n   at Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer.GetLatestChangesetId()"
    TargetSite: {SupportedEncoding ReadBOMEncoding(Boolean)}

QueryHistoryGetLatestChangesetId 的例外情况基本相同。从堆栈跟踪来看,TFS 在 2010 年到 2015 年之间处理编码的方式可能有所不同。

我正在寻找一种解决方案,允许我通过 API.

查询旧版 TFS 2010 和我们新的 TFS 2015

假设您使用相应的 VS 版本来使用 TFS。对于 Visual Studio 的每个主要版本,我们可能需要重新构建我们的 TFS 版本控制项目,以针对新版本的客户端对象模型。您想要的是构建引用 TFS 客户端 dll 并支持混合环境的项目。您可以查看 http://blogs.msdn.com/b/phkelley/archive/2013/08/12/checkin-policy-multitargeting.aspx 以找到适合您的方法。

希望对您有所帮助。

我可以使用API从TFS2010和TFS2015查询,下面是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TFSAPI
{
    class Program
    {
        static void Main(string[] args)
        {
            string project = "http://xxxxx:8080/tfs/DefaultCollection";
            NetworkCredential nc = new NetworkCredential("username","pwd");
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(project), nc);
            tpc.Authenticate();
            VersionControlServer vcs = tpc.GetService<VersionControlServer>();
            int cid = vcs.GetLatestChangesetId();
            string p = "$/ProjectName";
            var h = vcs.QueryHistory(p,RecursionType.Full,5);
            Console.WriteLine("Following are the latest 5 changeset in " + p +":");
            foreach (Changeset item in h)
            {
                Console.WriteLine("{0} {1}", item.ChangesetId, item.Comment);
            }
            Console.WriteLine("The latest changeset ID is:" + cid);
            Console.ReadLine();
        }
    }
}