2017-06-19 126 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); 
相關問題