How can i programmatically change the location of the working folder?

792 Views Asked by At

I'm using the .NET libraries provided by Microsoft for interaction with Visual Studio Team Services. I want to be able to change the local path of the working folder without using Team Foundation Power Tools or Visual Studio, only using the class library i'm making.

The problem is changes aren't being recognized by the source control in the new location. I can see the new working folder through the Power Tools menu for workspaces but it doesn't automatically detect changes inside that working folder.

This is my code for this functionality:

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;
        }

I'm clueless. The documentation for these .NET libraries is practically non-existent so i have no idea why this isn't working.

EDIT: Seems it started working after i did a refactoring of my code. The existence of conflicts also plays a role in things not working, sometimes.

1

There are 1 best solutions below

0
Marina Liu On

With below code, it can change a TFVC repo (TryTFVC) map path, such as change from C:\Users\TFSTest\Source\Workspaces\G1\TryTFVC to C:\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);