我正在使用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)}
QueryHistory
和GetLatestChangesetId
的异常基本相同。从堆栈跟踪看,TFS可能在2010年到2015年之间处理不同的编码。
我正在寻找一种解决方案,允许我通过API查询旧版TFS 2010和新的TFS 2015.
答案 0 :(得分:1)
我可以使用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();
}
}
}
答案 1 :(得分:0)
假设您使用相应的VS版本来使用TFS。对于Visual Studio的每个主要版本,我们可能需要重新构建我们的TFS版本控制项目,以定位客户端对象模型的新版本。您想要的是构建引用TFS客户端dll并支持混合环境的项目。您可以查看http://blogs.msdn.com/b/phkelley/archive/2013/08/12/checkin-policy-multitargeting.aspx以了解可能适合您的方法。
希望这会对你有所帮助。