2013-01-23 230 views
1

我喜欢通过C#代码签出文件,但我总是得到一个TF14098访问拒绝异常。 TFS管理员保证,我有结帐/编辑权限,在VisualStudio和tf.exe中,我没有任何问题来检出文件。TFS PendEdit导致TF14098:拒绝访问

这是我目前的C#代码:

非致命的失败:TF14098:

  const string tfsServer = @"http://MyServer:8080/tfs"; 
     const string fileName = @"$/MyFile.xaml"; 
     const string workspaceName = "MyWorkspace"; 

     using (TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)))   
     {    
      if (tfs != null) 
      { 
       WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName); 
       if (null != workspaceInfo) 
       { 
        var vcs = tfs.GetService<VersionControlServer>(); 
        Workspace workspace = workspaceInfo.GetWorkspace(tfs);         
        if(workspace == null){ 

         workspace = vcs.GetWorkspace(workspaceName, vcs.AuthorizedUser); 
        }     

        vcs.NonFatalError += VersionControlOnNonFatalError; 
        vcs.Getting += OnGetting; 
        vcs.BeforeCheckinPendingChange += OnBeforeCheckinPendingChange; 
        vcs.NewPendingChange += OnNewPendingChange; 

        if (workspace != null) 
        { 
         workspace.PendEdit(fileName); 
        }      
       } 
      } 
     } 

这与总是导致拒绝访问:用户我需要PendChange许可(个),$/MyFile.xaml。

很多这个错误研究我tryed检查权限后槽DOS窗口,我做了以下命令行:

tf checkout $/MyFile.xaml 

它导致文件的结帐没有任何问题! (如果我在文件所在的目录中)

有没有人有想法这个问题可能是什么?我的代码(用VisualStudio2012编写和执行的应用程序)与命令行结帐之间有什么区别?

感谢您的提示和提示! Patrik

回答

1

您的代码中的问题是,TfsTeamProjectCollection不适合您的路径,因为您从未设置集合名称(应该是类似于@“http:// MyServer:8080/tfs/DefaultCollection”的东西) 。 我从来没有检出通过使用API​​,但我确实开始这样的签:

WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); 
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(wi.ServerUri); 

VersionControlServer versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); 
Workspace workSpace = versionControlServer.GetWorkspace(wi); 

正如你所看到的,我用我的工作空间,而不是将其设置独立的搜索TeamCollection。这样做,你会得到正确的VersionControlServer做结账。

使用tf.exe工具的区别在于,您在本地工作区中运行它,因此该工具知道它在TFS中链接哪个项目以及哪个项目集合在哪个项目中。

+1

这是问题所在。最后它起作用。这花费了我很多时间和大量的研究。但对于奇怪的,我发现的所有例子都基于我上面发布的相同代码。奇怪,但我很高兴,它现在有效,我可以理解的原因。谢谢! – Patrik

+0

为了完成这个任务:我尝试了这个很好的例子。我仍然想知道,为什么样本(PendEdit)在我的环境中不起作用! http://blogs.msdn.com/b/buckh/archive/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer.aspx – Patrik

相关问题