2017-06-19 41 views
0

我使用Microsoft提供的.NET库与Visual Studio Team Services进行交互。我希望能够在不使用Team Foundation Power Tools或Visual Studio的情况下更改工作文件夹的本地路径,仅使用我正在创建的类库。如何以编程方式更改工作文件夹的位置?

问题是变化未被新位置中的源代码管理员识别。我可以通过Power Tools菜单为工作区看到新的工作文件夹,但它不会自动检测该工作文件夹内的更改。

这是我为这个功能的代码:

this.workingFolder = new WorkingFolder(this.workingFolder.ServerItem, newLocalFolder); 
      workspace.CreateMapping(workingFolder); 
      UpdateWorkspace(); 

public int UpdateWorkspace() 
     { 
      // Check if user has read permissions. 
      CheckWorkspacePermissions(); 
      // Update the workspace with most recent version of the project files from the repository. 
      GetStatus status = workspace.Get(); 
      Console.Write("Conflicts from checkout: "); 
      Console.WriteLine(status.NumConflicts); 
      return status.NumConflicts; 
     } 

我无言以对。这些.NET库的文档实际上是不存在的,所以我不知道为什么这不起作用。

编辑:似乎它开始工作后,我做了我的代码重构。有时候,冲突的存在也在不起作用的事情中起作用。

+0

我不能重现这个问题,新文件和修改的文件可检测。您的意思是在通过电动工具检入更改时显示“没有更改检入”。是否可以在旧的工作文件夹中检测到更改?如果您尝试使用新的工作区,结果如何? –

+0

是的,当我尝试检查它时说没有更改检入。 – sonicadv27

+0

是否可以在旧的工作文件夹中检测到更改?如果您尝试使用新的工作区,结果如何? –

回答

1

下面的代码,它可以改变一个TFVC回购(TryTFVC)地图路径,如从C:\Users\TFSTest\Source\Workspaces\G1\TryTFVCC:\Users\TFSTest\Source\Workspaces\G1\1变化:

NetworkCredential cred1 = new NetworkCredential("alternate credential username", "alternate credential password"); 
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://account.visualstudio.com"), cred1); 
VersionControlServer versionControl = tpc.GetService<VersionControlServer>(); 
Workspace ws = versionControl.GetWorkspace(@"C:\Users\TFSTest\Source\Workspaces\G11\TryTFVC");//older path 
WorkingFolder wf = new WorkingFolder("$/TryTFVC", @"C:\Users\TFSTest\Source\Workspaces\G1\1"); 
ws.CreateMapping(wf); //map with new path 
ws.Get(); 

GetStatus status = ws.Get(); 
Console.Write("Conflicts from checkout: "); 
Console.WriteLine(status.NumConflicts); 
相关问题