0

我想以编程方式连接到 TFS 并能够签出和签入文件。为此,我使用以下代码(省略了一些私人信息),但是,我得到“没有足够的权限错误”,我已经与管理员核实,他已经给了我读写权限,任何人都可以请帮我。这是代码:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace CodeGeneration
{
    public class CheckInTFS
    {
        public static void ProcessFile()
        {
            var tfs = new TfsTeamProjectCollection(new Uri("http://tfs"));
            var versionControlServer = tfs.GetService<VersionControlServer>(); 
            var workspace = versionControlServer.GetWorkspace(@"D:\Test");

            #region Checkout File

            var file = @"D:\EnumGeneration.cs";
            workspace.PendEdit(file);
            var pendingChange = workspace.GetPendingChanges();

            #endregion

            #region Checkin File

            workspace.CheckIn(pendingChange, "Test Comment!");
            #endregion
        }
    }
}

我收到的错误是这样的:

在此处输入图像描述

此外,我查看了此 MS 页面的权限,并且我拥有 GENERIC_READ 和 GENERIC_WRITE 权限。

4

2 回答 2

1

我找到了这个样本,试试这个,让我知道你在调整和运行它时是否仍然有权限问题

using System;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;

namespace TfsApplication
{
    class Program
    {
        static void Main(String[] args)
        {
            // Connect to Team Foundation Server
            //     Server is the name of the server that is running the application tier for Team Foundation.
            //     Port is the port that Team Foundation uses. The default port is 8080.
            //     VDir is the virtual path to the Team Foundation application. The default path is tfs.
            Uri tfsUri = (args.Length < 1) ? 
                new Uri("http://Server:Port/VDir") : new Uri(args[0]);

            TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);

            // Get the catalog of team project collections
            ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            // List the team project collections
            foreach (CatalogNode collectionNode in collectionNodes)
            {
                // Use the InstanceId property to get the team project collection
                Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

                // Print the name of the team project collection
                Console.WriteLine("Collection: " + teamProjectCollection.Name);

                // Get a catalog of team projects for the collection
                ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
                    new[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);

                // List the team projects in the collection
                foreach (CatalogNode projectNode in projectNodes)
                {
                    Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
                }
            }
        }
    }
}

取自这里

http://msdn.microsoft.com/en-us/library/bb286958.aspx

于 2013-08-22T18:52:19.067 回答
0

下面的代码片段起到了作用:

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TFS_SERVER));
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(FULL_FILE_PATH);
var workspace = workspaceInfo.GetWorkspace(tfs);
于 2013-08-22T21:32:30.920 回答