C# 撤消签出TFS
有没有办法在C#中以编程方式撤消签出 文件以编程方式签出,但是如果代码在执行时没有更改,我希望签出被撤消C# 撤消签出TFS,c#,tfs,C#,Tfs,有没有办法在C#中以编程方式撤消签出 文件以编程方式签出,但是如果代码在执行时没有更改,我希望签出被撤消 public static void CheckOutFromTFS(string fileName) { var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName); if (workspaceInfo == null) return; var server = n
public static void CheckOutFromTFS(string fileName)
{
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
if (workspaceInfo == null)
return;
var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
var workspace = workspaceInfo.GetWorkspace(server);
workspace.PendEdit(fileName);
}
上面的代码是我的签出代码。您可以使用Workspace.Undo方法撤消签出
我以以下方式完成了这项任务:
private const string ConstTfsServerUri = @"http://YourTfsAddress:8080/tfs/";
#region Undo
public async Task<bool> UndoPendingChangesAsync(string path)
{
return await Task.Run(() => UndoPendingChanges(path));
}
private bool UndoPendingChanges(string path)
{
using (var tfs = TeamFoundationServerFactory.GetServer(ConstTfsServerUri))
{
tfs.Authenticate();
// Create a new workspace for the currently authenticated user.
int res = 0;
try
{
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(ConstDefaultFlowsTfsPath);
var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
Workspace workspace = workspaceInfo.GetWorkspace(server);
res = workspace.Undo(path, RecursionType.Full);
}
catch (Exception ex)
{
UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(ex.Message));
}
return res == 1;//undo has been done succesfully
}
}
private const string constfsserveruri=@”http://YourTfsAddress:8080/tfs/";
#区域撤消
公共异步任务撤消挂起更改同步(字符串路径)
{
返回等待任务。运行(()=>UnpendingChanges(路径));
}
私有布尔撤消挂起更改(字符串路径)
{
使用(var tfs=TeamFoundationServerFactory.GetServer(constfsserveruri))
{
tfs.Authenticate();
//为当前经过身份验证的用户创建新工作区。
int res=0;
尝试
{
var workspaceInfo=Workstation.Current.GetLocalWorkspaceInfo(ConstDefaultFlowsTfsPath);
var server=new-tfstreamprojectcollection(workspaceInfo.ServerUri);
Workspace=workspaceInfo.GetWorkspace(服务器);
res=workspace.Undo(路径,RecursionType.Full);
}
捕获(例外情况除外)
{
UIHelper.Instance.RunOnUiThread(()=>MessageBox.Show(ex.Message));
}
return res==1;//撤消已成功完成
}
}
您是否尝试过workspace.Undo()?工作起来很有魅力!谢谢:)你能提供它作为一个答案,这样这个问题可以被设置为被回答吗?