VersionControlServer异常抛出

时间:2014-12-10 09:35:49

标签: c#

我在TFS中很新,我的问题是,当我运行上面的代码时,我得到异常:附加信息:TF31002:无法连接到此Team Foundation Server:https://tormentorslayer.visualstudio.com/。 由GetService();引起的。是否有人知道可能的原因是什么?

using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Framework.Client;
using System.IO;
using System.Threading;
using System.Net;

namespace BackEndDev {
    class Program
    {
        static void Main(string[] args)
        {

            //1. Connect to TFS
            string teamProjectCollectionUrl = "https://tormentorslayer.visualstudio.com/";
            NetworkCredential myNetCredentials =
                 new NetworkCredential("username", "password");
            ICredentials myCredentials = (ICredentials)myNetCredentials;
            TfsTeamProjectCollection teamProjectCollection =
                new TfsTeamProjectCollection(new Uri(teamProjectCollectionUrl), myNetCredentials);
            VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();

            //2. Scan history
            var tp = versionControlServer.GetTeamProject(@"MyCollection");
            var path = tp.ServerItem;
            path += @"C:\Users\username\Documents\Visual Studio 2013\Projects";

            var results = versionControlServer.QueryHistory(
                                path,                         // The item (file) to query history for
                                VersionSpec.Latest,           // We want to query the latest version
                                0,                            // We're not interested in the Deletion ID
                                RecursionType.Full,           // Recurse all folders
                                null,                         // Specify null to query for all users
                                new ChangesetVersionSpec(1),  // Starting version is the 1st changeset        
                // in TFS
                                VersionSpec.Latest,           // Ending version is the latest version
                // in TFS
                                int.MaxValue,                 // Maximum number of entries to return
                                true,                         // Include changes
                                false);                       // Slot mode

            //3. For each history entry, scan files and add LOCs per file type

            foreach (var scanFiles in results)
            {
                Console.WriteLine(scanFiles);   
            }

0 个答案:

没有答案