【问题标题】:Error in checkout and checkin files in TFS programatically despite having permissions尽管具有权限,但以编程方式在 TFS 中签出和签入文件时出错
【发布时间】:2019-02-14 18:34:52
【问题描述】:

我想以编程方式连接到 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
        }
    }
}

我收到的错误是这样的:

另外,我查看了来自This MS Page 的权限,并且我拥有 GENERIC_READ 和 GENERIC_WRITE 权限。

【问题讨论】:

  • 我确实有 GENERIC_READ 和 GENERIC_Write 权限,我还需要哪些其他权限?我从这里检查了权限:msdn.microsoft.com/en-us/library/ms252587%28v=vs.100%29.aspx
  • 您是否以管理员身份运行 Visual Studio?
  • 有时最好进行试错,尤其是使用权限。尝试拥有所有权限并查看是否出现此错误。如果可行,请尝试删除一堆权限,然后再做一次。

标签: c# tfs tfs-sdk


【解决方案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

【讨论】:

    【解决方案2】:

    下面的代码 sn-p 成功了:

    var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TFS_SERVER));
    var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(FULL_FILE_PATH);
    var workspace = workspaceInfo.GetWorkspace(tfs);
    

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 1970-01-01
      • 2014-01-29
      • 2012-08-06
      • 2014-11-05
      • 2011-04-15
      • 2012-10-28
      • 2016-08-20
      • 1970-01-01
      相关资源
      最近更新 更多