What's the big deal about Workspaces in TFS - tfs

What's the big deal about Workspaces in TFS.
I just want to monitor some folder for changesets and checkins and copy them to some other tfs folder, and I don't understand why workspaces are so
important. There is not one accepted solution in stackoverflow that
does not mention workspaces. Why do I need workspaces to use tf
commands, such as tf checkin, tf add, etc. It's pretty frustrating..
thanks..

Please understand the workspace first. TFS stores your code, but when you begin to make changes to the code, those changes have to happen on your local machine. The code files need to be checked out from TFS to a local area on your computer. A "workspace" in TFS defines where the code resides locally.
In essence, a workspace is a folder, or multiple folders, mapped to areas in TFS. When code is checked out of TFS, the code is stored locally based off your workspace mappings. When you make changes to your code files, you are making those changes locally, to the files contained in your workspace.
One of the main reasons for workspaces is isolation. It provides a private sandbox where code changes can be made without having to worry if the changes will affect other team members. The changes remain in the local workspace until are checked into TFS.
For tf commands, it's designed based on the workspace for version control, please refer to below articles to understand more about the workspace and tf commands:
An introduction to TFS Workspaces
Workspaces in Team Foundation Server
Using TFS Source Control From Command line tf.exe

Related

TFS Server checkin error - could not find file - Server Related and Command Line

This relates to question,
TFS checkin error - could not find file
"When checking in my project I get the error:
Could not find file 'C\blah blah blah'.
I have a feeling this might be a file from an old project I deleted.
I have tried deleting my TFS connection and workspaces.
The Solution was:
This will happen when TFS has some changes staged that no longer exist on the file system. For instance, if you add some files in Visual Studio (which adds them to the changes list), delete them directly from the file system, then attempt to check in the changes, it will complain that it could not find the file(s).
To remove these changes from the list, you can open Source Control Explorer (View > Other Windows > Source Control Explorer) and either Delete the nonexistent files or right-click on the offending files and Undo Pending Changes.
You can also undo these specific changes from the Pending Changes panel in Team Explorer.
Follow up Question:
So my question is,
how do I conduct the equivalent of this in the TFS Server? It continuously happens multiple times on our team.
This works on a person's desktop, but whats the equivalent commandline in the TFS server, and can I incorporate this in my build steps?
You delete files from TFS in the wrong way. the TFS server doesn't know your local file system, if you deleted a file from your local folder the file still exists on TFS.
This is the reason for the issues and errors. if a developer wants to delete a file and he deleted the file from the local folder and then got the error Could not find file and to solve it he does "Undo pending changes" so the file still exists on TFS and when another developer see the file in his system he also deleted it locally and he also will get the error in the check-in.
So, if a developer wants to delete a file from TFS he needs to right-click on the file and "Delete" and "check-in". if he already deleted it locally he can do the "delete nonexistent files" and "check-in". now each developer when he does "Get latest" not will get the file.
You can also delete files with a tf.exe command line in the delete command:
tf delete [/lock:(none|checkin|checkout)] [/recursive] [/login:username,[password]] itemspec
During the build, you can add a command line/Power Shell task and run the tf.exe.
You can undo another person's changes from the commandline using:
tf vc undo /workspace:workspacename;owner $/project/path/to/file
You can get this information by calling:
tf vc status $/project/path/to/file /user:*
This allows you to remove pending changes from the server, though it won't cause the files to be reverted on the workstation of the developer in question.
Both commands offer a /recursive option to undo multiple files under a specific path at once.
If you're using Visual Studio 2015 or earlier, then you can use the TFS Power Tools to add a "Find by status" option to the Visual Studio Source Control Explorer. This has unfortunately not made it into Visual Studio 2017 and there are no TFS Power Tools for Visual Studio 2017.
The TFS Sidekicks offer a Status Sidekick screen, which allows you to query all files currently checked out for edit in server workspaces and allow you to undo them centrally.
Preventing the issue altogether
To prevent the issue altogether you have a few options. You can switch to Local workspaces, instead of server workspaces. Those auto-detect local changes and don't register changes on the TFS server itself. Read more about local workspaces.
You can perform the deletes from the tf vc command line instead of using other tools to delete files and folders, for example:
tf vc delete $/project/path/to/file
The delete command also has a /recursive option. Using this command will not only update your local folder, but will also update the server workspace.

TFS: How do I get a list of managed files in my enlistment?

In tfs, how do I get a list of files in my working directory that are being managed by tfs? I don't care if I've checked them out or not (if I did, tf status would be the obvious choice). I just care whether or not tfs is tracking changes for them or not.
I want to use this like I use hg locate for Mercurial. I want to search through all the files that are not temporary files or build products of some kind, things that are part of the base source code, for something that shows up in the build products, but I don't know where it comes from.
Try to use LocalVersions command. (The newly be added file won’t be list)
You could use tf workflod command. Which could displays information about the mappings between your workspace folders and the folders on the server for Team Foundation version control.
The following command displays the working folder mappings for the workspace in the current directory:
C:\projects>tf workfold
If you want to list the working folder mappings for a different workspace, you can specify the /workspace:workspacename parameter.
C:\>tf workfold /workspace:My_Other_Workspace
Required Permissions
To use the workfold command, you must be the owner of the specified or implied workspace or have the global Administer workspaces permission set to Allow.

How to delete all the worskpace that are mapped to a physical folder in TFS?

I am using TFS 2013.
What would a command to Delete All the WorkSpace belonging to any Agent that is mapped to a specific folder look like?
For Example all the Workspace that are mapped to "C:\ABC\Common" should be deleted.
Want to add script as pre build Task
I would use the (free) tool TFS Sidekicks to do this. You can easily view all the workspaces for that computer/agent, and see the mappings for each one. Also you can easily delete all the relevant workspaces from the tool in a nice GUI.
http://www.attrice.info/cm/tfs/

tfpt migrate for TFS doesn't do anything

I'm trying to use tfpt to migrate a shelveset from a source branch into a target branch, but it doesn't appear to do anything...not that I'd expect much more...but any chance anyone knows what's wrong? I'm following the instructions correctly I think...
I've got:
tfpt unshelve "DbMigrations" /migrate /source:$/TeamProject/Main /target:$/TeamProject/Releases/7.20
What happens after you run the command? You need to have a few things set up before migrating:
A workspace that encompasses both the source and target branches.
You need to run the command in a folder within the source.
Once you run the command you should be asked to merge the changes from the original shelfset into the destination branch and resolve any conflicts, which finally pends a changeset on your client. Nothing is touched on the server until you check that changeset into TFS itself.
I experienced the same problem and I could not get it to work by specifying the shelveset name. However, I discovered that if you remove the name of the shelveset altogether, TFS will pop up a window with a selection list of available shelvesets to choose from. Select the desired shelveset and perform all other merge operations as per normal.
Example: c:[mapped workspace target path] > tfpt unshelve /migrate /source:"$/Sourcepath" /target:"$/targetpath"
You need to use the branch paths on the TFS server, not your local machine. To find the paths, go to source control explorer in visual studio, right click the branch, advanced > properties, and you want the branch name, not the local path. If the path has spaces, wrap it in double quotes.

TFS 2010 Windows Shell Extensions, how do I connect to a workspace?

I have VS 2010 and a TFS 2010 server set up and it's all working fine. I've checked out files to my local hard drive.
I installed the TFS Power Tools to be able to get to TFS through context menu in Windows. If I right click in a TFS project on my hard drive I get all the icons and it works.
My question is that how do I get the TFS menu if I have no source code from TFS on my hard drive?
Regards,
Magnus
"how do I get the TFS menu if I have
no source code from TFS on my hard
drive?"
First, you need to define a workspace and map server (source control) paths to local directories. You can do this in either of two ways:
Use the tf workspace command to define a new workspace.
Use Source Control Explorer to Create a Workspace and Get Files.
Once you've setup your workspace, you can right click any file or folder in your workspace you will find a Team Foundation Server option, expand it and you will see other version control options like checkout, check-in etc.

Resources