Original post: http://teamsystemrocks.com/blogs/omarv/archive/2006/03/08/725.aspx
As more of our clients adopt Team System, it has been quite common lately for me to talk about Team Foundation Version Control workspaces. I often find myself having the exact same conversation with different people as they are trying to get from or add files to the version control repository [ NOTE: These are people that did not take our training ;-) ].
It all starts with something along the lines of "but the item is greyed out in Source Control Explorer"... If this is happening to you, you need to create a workspace mapping.
A workspace, according to the VSTS help "Represents a client-side copy of the files in the repository that you want to work in." What that means is that the TFS server needs to know where to put the files on your local drive when you perform a Get operation; and you have to specify it, there are no defaults and the server will not guess the location. Notice that I said 'server', this information is tracked on the server.
Now, you may have been working with VSTS and Source Control and not had any issues with workspaces. When you create a new solutions and select the 'Add to source control' checkbox, this creates a workspace mapping for you; I personally do not like this mapping because it is very specific to that solution, it goes to the solution folder level. This could potentially add a lot of mapping entries to your workspace definition, making it confusing and hard to manage. I personally like to have mappings at the Team Project root level. Mappings are recursive so once you define a top level mapping, your entire local folder structure could be created automatically and it will be exactly the same as your SCC folder structure.
Depending on your folder structures, you may have to end up with many mapping entries anyway. But for new projects I like to have my Team Project root (i.e. $/MyTeamProject) mapped to a folder of the same same name in my local drive, and this folder would be under C:\TeamProjects. I create these project mappings before I start working on any Team Project.
To create a workspace mapping select File -> Source Control -> Workspaces, select the workspace you want to modify (ideally you will only have one to choose from) then click Edit and add your entry in the grid at the bottom of the Dialog Box.
Workspaces are per machine, per user account. In other words, a user account can have a different workspace definition for each computer he or she uses, and there can be multiple workspaces in a given computer (if multiple user accounts are used to log in to the computer). Workspaces cannot be shared, which means that if to users of $/MyTeamProject log in to the same computer, they cannot both have that folder mapped to C:\TeamProjects\MyTeamProject, an alternative to this would be to create the 'TeamProjects' local folder under the 'My Documents' folder of each user account, but this could potentially cause your solution and VS project files to have very long location paths.