TFS2012: How to delete a workspace using the tf command
Today while I am writing another blog post, I encountered the following error
Exception Message: The working folder C:\Builds\5\MyTeamProject\UnitTestProject1\src is already in use by the workspace 6_5_TFS2012Build1;TFS2012BUILD1$ on computer TFS2012BUILD1. The Build Agent TFS2012Build1 – Agent1 is running as a different user Administrator and local paths can only be mapped to a single workspace. To resolve this issue, you can configure the Build Service to run as the user who owns the conflicting workspace, or you can delete the workspace using the ‘tf workspace’ command. (type WorkingFolderInUseException)
I received that error because, I changed the run as service account for the Build Controller. From a machine that has Visual Studio installed, open the VS command prompt.
Then, the first thing you want to do is check what switches TF workspace has by running the following command
tf workspace /?
To learn more about the switches or arguments, check this msdn article http://msdn.microsoft.com/en-us/library/y901w7se(v=vs.100).aspx
You can also use the tf workspaces to target multiple workspaces or to list all workspaces for a collection
tf workspaces /collection:http://tfs2012express:8080/tfs/defaultcollection Collection:http://tfs2012express:8080/tfs/defaultcollection
The above will return you the workspaces on the current machine. If you want to view all workspaces, you need to use the /computer switch
tf workspaces /collection:http://tfs2012express:8080/tfs/defaultcollection Collection:http://tfs2012express:8080/tfs/defaultcollection /computer:*
In my case, I am using the following switches
tf workspace /delete /collection:<a href="http://tfs2012express:8080/tfs/defaultcollection 6_5_tfs2012build1;tfs2012build1$
Type Yes and press enter