Move TFS workspace to new machine - visual-studio

I got a new computer and I have to move my TFS workspace. I found confusing info online, is this the correct approach?
Add TF server in VS of new machine
Copy folders from old machine to new machine (I have some files with pending changes)
Update TF workspace in new machine using the command:
tf workspaces /updateComputerName:oldCompName /s:"serverURL"
In VS (new machine), map projects. Is this required?

If you copied the entire workspace folders, then the map projects is not required, otherwise you have to map the projects (manage the workspace and map to the copied folder).
For example, if the original workspace is mapped to D:\Ad-workspace\2017\SCRUM-TFVC, then you have to copy the folders to the same path in the new machine.
Actually, you don't need to copy the workspace, just create a shelveset for the pending changes in the old machine, then connect to TFS from the new machine and map to a new workspace, then find the shelvset and unshelve, all the pending changes will be back to your new workspace.

TFS workspaces are identified by the owner, the computer name and the workspace name. If your new computer has a new name, you need to update your existing TFS workspaces to reflect that change.
Your process is correctly and the last step is required. After establish the mapping, you may get a promote message:
Newly mapped items will not be download, until you execute a get...
You could perform a get. Then copy your back-up files/folders which copied from main branch to the new dev branch. Windows system will judge to replace files and add new files.(It may take some time) After this, TFS system will auto detect the changes in local and will list them as new pending changes.
Everything get back to the same as you work in old machine.

Related

Visual Studio creating multiple/ additional workspaces

I started using TFS since VS2010. By that time I already created my own TFS server (myname.visualstudio.com). My problem is that I created a new project on the my TFS website (the one with the dashboards). Then when I go to VS2017, and connect to that new project, it asks me to map and get it as expected. Instead of just clicking "Map & Get" button, I instead clicked advanced so that I can configure everything.
On the workspace configuration dialog, I noticed that VS names it as "MYPCBLABLA_1". If I try to remove the "_1", VS says that "the workspace blablabla already exists on computer blablabla", and does not let me use my existing workspace name.
Why does it do so? Can I not use only 1 workspace? From what I understand of workspaces, it is the container of my projects, so different workspace, different set of projects. But what are they really?
Additional info:
I don't know if this helps but on the past, I used to format my PC many times, I'm not sure if that affects the mappings or workspace names when I use VS after reformatting.
Workspaces are maybe the least well-understood feature in TFVC. And you are right in saying they're a way to isolate different sets of files from a TFVC repository.
A lot of people configure a new workspace for a specific project or set of solutions, but let's look at some of the ways workspaces can be used in detail:
Hotfixes: you may need to create a hotfix for something happening now, but you have pending changes in your existing workspace. Instead of shelving these changes, performing a "Get Specific version" on the bugged version, you can also create a new workspace in which to solve this particular problem. After completing the fix you can then continue working with the other workspace without needing to do anything.
Experiments: you may want to do some major refactoring, restructure source control or some other highly impactful operation. Doing this in a new (temporary) workspace helps you prevent messing up your normal work area.
Reviewing other peoples changes: When performing a review on another person's changes, you may want to have a local copy so you can run, annotate and play with the other person's code. Instead of taking these changes into your own workspace, you can easily bring these into a temporary workspace, which you can safely delete afterwards.
Performing a merge, while you are working on other changes: It may be the case that you're working on a new feature an already have some changes merged back to another branch when a release needs to be shipped. In order to prepare this release, without picking up changes or overwriting work in progress in your current workspace, it's often easier to perform these kinds of release activities in a temporary workspace, that way you know that the work is always done on the exact version in source control.
Preventing accidental changes to important branches: By putting your production branch in a separate workspace, you can't accidentally combine changes from say Development and Main into a single check-in. Since Visual Studio often auto-selects all pending changes in the workspace, this may cause unintended changes to your master/main branch. I've written a Check-in policy to prevent these issues, but having separate workspaces is a much safer solution.
Working with multiple developers on the same workstation/server: in some organisations, developers use a remote desktop to a central beefy server to do changes. To ensure each developer has his own set of files, each developer gets his/her own workspace. An alternative is to make the workspace public, which allows multiple developers to use the same workspace folder. But this often leads to all kinds of unexpected issues.
Browsing an old version of the code: if you need to review/compare an older version to a new one, you can often get away with the folder diff view in Visual Studio, but if you need to do more thorough comparisons, you may want to have 2 copies of the same folder in your TFVC repo. Creating two workspaces will allow you to have two different versions of the same folder on your local disk.
Prepare a special version for merges or labels: You can merge and label the workspace version of a set of files. You can create a workspace and then use Get Specific Version to fetch specific versions of specific files, these can all come from different changeset versions. Once you're satisfied, you can perform the label or merge or branch action to store this specific workspace version configuration on the server.
As you can see, Workspaces allow you to do parallel development on one machine, isolate changes etc.
Be creative
As you can see, workspaces are a very powerful concept. Usable for a lot of operations. But you need to understand the concept thoroughly. Many developers don't understand exactly what workspaces are and how they work, they're missing out of some of the most powerful concepts of TFVC.
Consolidating and cleaning up
In your case you now have two workspaces. In order to consolidate these (if you want to), you can unmap the folders from your _1 folder and then map these same folders in your original workspace. You can also delete the _1 workspace from the TFS Server and then update the mappings of the original workspace.
Remember that workspaces are stored on your local machine, but that the TFS server also has a registry of who mapped which TFVC folders to which workstations. So simply deleting files from your local disk is not sufficient. You need to save these changes to the TFS server (this happens automatically after performing a get operation after changing the mappings).
To check which workspaces are registered to your workstation on the TFS server, use:
tf vc workspaces /computer:YOURWORKSTATIONNAME
Then delete old workspaces with
// DELETE the local workspace
tf vc workspace /delete:WORKSPACENAME
// DELETE the workspace registration on the TFS server
tf vc workspaces /remove:WORKSPACENAME
To prevent the creation of a new workspace by VS, I:
Create a local folder to which I’ll map the content of the remote repository;
In VS, connect to the remote repository;
In VS, open Source Control Explorer and navigate to the content I need; VS will show a “not mapped message”.
Click on that message and map locally.
This guarantees that no other workspace will be created, and the current one will be used.

Importing checked out files on TFS from one machine to another

I have new files added on TFS and some other checked out but on my older workspace. Now my machine is changed and I want to have those files on my new workspace.
Is there any way to have these changes replicated/imported to my new workspace?
You have to check in the changes or create a shelveset on your old workstation and take a get latest on your new computer.
http://msdn.microsoft.com/en-us/library/ms181403(v=vs.80).aspx
If you still have access to your old machine, you can either check in the changes or put them on a Shelveset (if you don't want to check them in for everyone to see). Then on your new machine either do a Get Latest Version (when you had checked the code in) or Unshelve the changes to your new machine.
If you don't have access to your old machine, then these changes are not available. TFS doesn't get the changes version of your files until you either check in or shelve. You'll have to consider them lost and unrecoverable.
If you have access to the old machine, but the old machine can no longer access TFS, copy the old workspace to the new machine and then use the Compare folder option to merge your changes into your new workspace.
To prevent accidentally losing your changes you can install an extension which automatically shelves your changes.

How do you force the deletion of a TFS 2010 workspace on a client when the TFS Server no longer exists?

I currently have a TFS 2010 Server running on SERVER-1. On my client (MY-CLIENT) I have VS2010 running and have a workspace associating SERVER-1 with \MY-CLIENT\Development. All is good.
I was playing around with setting up a different instance of TFS on SERVER-2. On my client, I deleted the original SERVER-1 workspace and created a new workspace associating SERVER-2 with \MY-CLIENT\Development. All is good.
Having finished my experiments with TFS on SERVER-2, I re-imaged the machine (deleting the TFS Server on SERVER-2).
I then went back to my client machine, reconnected to TFS on SERVER-1 and attempted to remap source control to my Development folder. However, am now receiving the error "The path \MY-CLIENT\Development is already mapped in workspace MY-CLIENT;SERVER-2\Steve." Now I have a problem.
So, I gather from this that I should have first deleted the SERVER-2 workspace BEFORE re-imaging the machine. Unfortunately, I did not do that.
Poking around in some forums, I realize that I can use a command line tool to perhaps delete it:
tf workspace /delete MY-CLIENT;SERVER-2\Steve
However, when I run this, I get a message indicating that "Team Foundation services are not available from server http://SERVER-2:8080/tfs/development."
So the question, then, is how do I force deletion of the SERVER-2 workspace on my client so that I can re-create my old SERVER-1 workspace?
The working folder mappings for all the local workspaces is stored in the version control cache file. This allows you to bootstrap TFS clients, allowing them to locate the server information for a given local folder. In addition, it will provide the information for this test you're seeing, that prevents a local folder from being mapped to two different servers.
In order to clean this up (without trying to connect to the server), you can use the tf workspaces command (note the pluralization - the workspaces command operates on the list of workspaces, the workspace command operates on a workspace and generally requires connectivity to the server that workspace is located on.
To delete all workspaces for your deleted project collection, you can do:
tf workspaces /remove:* /collection:http://server-2:8080/tfs/DefaultCollection
(Obviously replacing the project collection URI with the URI for your deleted server.)
I had exactly the same issue: After moving TFS server to another machine, I couldn't map to a local folder in VS2012 on the old machine because it was still associated with an old Workspace that TFS denied all existence of. After many hours (and days) searching Google and trying different things, none of which worked (including all the "tf" commands, deleting the local cache etc), this is how I eventually solved it:
Edit the actual TFS collection database on the TFS server using SQL Management Studio Express (e.g. "Tfs_DefaultCollection")
Look for the "dbo.tbl_Workspace" table and edit it
You should see your "ghost" workspace(s) in here
Delete the rows
All is right in the world
The workspaceowner parameter on the delete command is optional. Can you issue the delete without that parameter, or will that damage another MY-CLIENT workspace?

How to map existing folders (which are moved to new machine) with the TFS without need to download the entire data from TFS?

Earlier I had mapped my local folders to the TFS. I had to change machine/computer for some reason. So I copied all the folders to the new machine.
Now when I try to map the TFS folders to the existing folders on the new machine, it always shows Not Downloaded under the Latest column of the Source Control Explorer (VS 2010). I can get the latest version but it's very time consuming.
Can someone suggest a way to establish relationship between existing folders and the TFS folders in lesser time?
What you need is to have a workspace in your new machine that only has the mappings of your folders in TFS. If you just map your folders in your workspace, when you do a get, only files in your folders are downloaded locally, not the entire version control tree in TFS. Since you can copy your folders from one machine to another, downloading them from the server again shouldn't take more time than that.
From Source Control Explorer, let say you use the default workspace:
If you have jus a few folders, right click at each one and choose "Map to Local Folder", then specify the local path.
Alternatively, you can map from the root folder (of your folders), then cloak the ones that you don't want to download. Open the drop-down list of workspaces and choose "Workspaces", then choose to edit your workspace, then you can add and cloak the mappings of your folders like this:

Copy TFS Working folders list from one workspace to another

I got new working machine and because our TFS server is located very far from jobsites I want to avoid downloading all source codes again (several GBs) so want to move my old workspace to new one. I have copied all projects via LAN and Working folders list in Workspaces is empty in VS on new machine.
So how to move all items from old workspace to new one without adding them manually and downloading all the data again?
It's super easy to migrate your workspaces from an old machine, given your exact scenario. See this other thread on Stackoverflow:
Import Visual Studio TFS workspaces
Shelve everything in your workspace and unshelve it to the new computer. When you create the shelfset, make sure that "Preserve pending changes locally" is not checked.
This will, effectively move the workspace from one computer to another.
** Update based on question being updated **
I don't think there's an easy way for you to do what you are wanting to do within a workspace. Instead, you should be looking at the TFS Proxy. When you implement the proxy, it sits between your workstation and the TFS repository, and helps proxy gets, check-outs, and check-ins to help speed up your interaction with TFS.

Resources