Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TFS/从C签出文件#_C#_Tfs - Fatal编程技术网

C# TFS/从C签出文件#

C# TFS/从C签出文件#,c#,tfs,C#,Tfs,除了将TFS用于源代码控制之外,我对TFS没有太多的经验。我正在开发一个C#应用程序,它需要修改由TFS控制的文件。在我的C#应用程序中,如何签出通过TFS控制的文件 谢谢-Randy您可以使用PendEdit使文件可写,对其进行更改,然后将其添加到挂起的更改中,最后将其签入 下面是一些创建文件夹结构然后签入的代码(与您需要的非常类似) 使用其他解决方案给了我权限问题 下面是使用tf.exe签出文件的另一种方法: //Checkout file Process proc = new Proces

除了将TFS用于源代码控制之外,我对TFS没有太多的经验。我正在开发一个C#应用程序,它需要修改由TFS控制的文件。在我的C#应用程序中,如何签出通过TFS控制的文件


谢谢-Randy

您可以使用PendEdit使文件可写,对其进行更改,然后将其添加到挂起的更改中,最后将其签入

下面是一些创建文件夹结构然后签入的代码(与您需要的非常类似)


使用其他解决方案给了我权限问题

下面是使用
tf.exe
签出文件的另一种方法:

//Checkout file
Process proc = new Process();
proc.StartInfo = 
    new ProcessStartInfo(
        @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe", 
        string.Format("checkout \"{0}\"", fileLocation)
    );
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();

对于那些希望使用第一个解决方案并解决权限问题的用户,您可以使用以下代码来使用当前凭据,这将替换“TeamFoundationServerFactory.GetServer”调用,然后使用TfsTeamProjectCollection(tmPrjColl)获取VersionControlServer:

using Microsoft.TeamFoundation.Client;
using MTVC = Microsoft.TeamFoundation.VersionControl.Client;
using MVSC = Microsoft.VisualStudio.Services.Common;

MVSC.VssCredentials creds = new MVSC.VssCredentials(new MVSC.WindowsCredential(true));
using (TfsTeamProjectCollection tmPrjColl = new TfsTeamProjectCollection(new Uri("<source control URL>"), creds))
{
    MTVC.VersionControlServer verCtrlSvr = tmPrjColl.GetService<MTVC.VersionControlServer>();
    ...
}
使用Microsoft.TeamFoundation.Client;
使用MTVC=Microsoft.TeamFoundation.VersionControl.Client;
使用MVSC=Microsoft.VisualStudio.Services.Common;
MVSC.VssCredentials creds=新MVSC.VssCredentials(新MVSC.WindowsCredentials(true));
使用(tfstreamprojectcollection tmPrjColl=newtfstreamprojectcollection(新Uri(“”,creds))
{
MTVC.VersionControlServer verCtrlSvr=tmPrjColl.GetService();
...
}

您不应自行设置可写文件。Workspace.PendEdit()为您完成这项工作。可写但未签出的文件表示不一致的状态,在执行诸如获取和重命名之类的操作时可能会导致不必要的冲突。在这里您实际如何传递凭据?请注意,如果文件路径为空,则会出现问题:命令行应为“签出”{0}
using Microsoft.TeamFoundation.Client;
using MTVC = Microsoft.TeamFoundation.VersionControl.Client;
using MVSC = Microsoft.VisualStudio.Services.Common;

MVSC.VssCredentials creds = new MVSC.VssCredentials(new MVSC.WindowsCredential(true));
using (TfsTeamProjectCollection tmPrjColl = new TfsTeamProjectCollection(new Uri("<source control URL>"), creds))
{
    MTVC.VersionControlServer verCtrlSvr = tmPrjColl.GetService<MTVC.VersionControlServer>();
    ...
}