4

Using Developer Command Prompt for VS 2019

I am able to see a list of all my workspaces.

tf workspaces /collection:"https://dev.azure.com/[ORGANIZATION]" /owner:*

I can then delete my local workspaces using:

tf workspace /delete [WORKSPACE];"[OWNER]"

If I launch Visual Studio and then rerun first command the workspace returns.

The same thing occurs if I delete the workspace from the VS UI. It will reappear as soon as I click map & get to create a new workspace of same name just deleted.


NOTES

Prior to relaunching Visual Studio I also tried:

  1. Clearing the cache folder here: C:\Users\[NAME]\AppData\Local\Microsoft\Team Foundation\8.0\Cache
  2. Deleting all my local workspace files here: C:\Users\[NAME]\source\Workspaces

EDIT

After some testing I believe the issue may relate to an old workspace that had the same name. I cannot delete the old workspace because when I try to delete old non local databases I receive:

ERROR:

The workspace [WORKSPACE];[OWNER] does not exist.

I now believe the old workspace is a trace from when I migrated to Azure from old TFS.


QUESTIONS

  1. How can I delete ALL workspaces?
  2. Can workspaces be deleted from the Azure Dev Ops portal?
  3. How can you delete non local workspaces?
DreamTeK
  • 32,537
  • 27
  • 112
  • 171

2 Answers2

5

To delete an existing workspace, you must be the owner or have the global Administer workspaces permission set to Allow.

You could also try to use onwer uniq ID instead of name

tf vc workspaces ws_3_3 /computer:* /format:xml /collection:https://dev.azure.com/patricklu/

ws_3_3 is your workspace name which want to delete, collection just type your collection url In the prompt up window type your address to connect to the url(If there is).

After this it will return some information such as below:

enter image description here

With info of owner uniq ID

Then you just need to use tf workspace /delete the command, in my sample it’s using:

tf workspace /delete ws_3_3;fb46f066-9122-4342-94c4-93b7526a3545

enter image description here

Simply type yes, it will delete the workspace. "Unable to determine the source control server" This may caused by you didn't include the collection url when you try to delete a workspace not locally.

1. How can I delete ALL workspaces?

There is not a command to delete all workspaces in company, you have to do it one by one.

2. Can workspaces be deleted from the Azure Dev Ops portal?

No, you couldn't do this. You should either use command line or through Visual Studio UI as below:

enter image description here Hope this helps.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thanks Patrick. This does offer some insight. I deleted with unique id and again it is deleted however relaunching VS restores it. I have also tried deleting the workspace using the ui in vs but as soon as I click `map & get` to create a new workspace the old one immediately restores. – DreamTeK Sep 03 '19 at 07:33
  • After including collection in delete command I get error instead. `the collection does not exist` Can you offer further insight from your wisdom? – DreamTeK Sep 03 '19 at 08:14
  • @DreamTeK What's detail command are you using? Were you able to see this specific workspace through `tf workspaces /computer:* /owner:* /format:xml` If so try to delete it without the collection url just use GUID and format as suggested above `tf workspace /delete ws_3_3;fb46f066-9122-4342-94c4-93b7526a3545` Besides, you could take a look at this similar link https://developercommunity.visualstudio.com/content/problem/267507/cant-delete-an-abandoned-vsts-workspace.html – PatrickLu-MSFT Sep 03 '19 at 08:35
  • @DreamTeK According to your latest update `After some testing I believe the issue may relate to an old workspace that had the same name. I cannot delete the old workspace` Seems this is caused by an obsolete workspace. After deleted it, then try to clear Clearing the cache folder here: C:\Users\[NAME]\AppData\Local\Microsoft\Team Foundation\8.0\Cache. Close Visual Studio and re-load it, which may do the trick. – PatrickLu-MSFT Sep 03 '19 at 08:37
  • Thanks Partrick but I already tried that. It makes no differance. – DreamTeK Sep 03 '19 at 08:51
  • @DreamTeK So as suggested elsewhere [Team Foundation Sidekicks](http://www.attrice.info/cm/tfs/) is also a good way of removing workspaces - both your own and others. It does not work out of the box on a computer with only VS 2019, but there is a workaround for this.-- [Fix TFS Sidekick 2015 to work without VS2015](https://www.dotnetcatch.com/2017/03/03/fix-tfs-sidekick-2015-to-work-without-vs2015/) Or you could just install Vs2015 , try to use Team Foundation Sidekicks – PatrickLu-MSFT Sep 03 '19 at 09:00
  • 1
    I was looking at sidekicks but could not get it working with 2019. I will try and see if I can get the fix to work. Cheers. – DreamTeK Sep 03 '19 at 09:06
  • Hi @DreamTeK Any update on this issue, have you figured it out? Did you get a chance to implement the solution with using Team Foundation Sidekicks? – PatrickLu-MSFT Sep 16 '19 at 09:46
  • Hi Patrick, thanks for following up on this. I was not able to get Sidekicks working on 2019 unfortunately and was unable to delete any projects not setup locally. I ended up creating another workspace as a workaround. I am still curious how to delete a workspace that was setup on another machine. – DreamTeK Sep 16 '19 at 09:55
  • @DreamTeK Thanks for quickly response. Sorry to hear this. `I am still curious how to delete a workspace that was setup on another machine.` Both using UI in VS - remote workspace and use tf workspace /delete should work. You just need to make sure the account you used to run command have enough permission.To be honest, there must be something special issues kind of cache with that particular workspace which cause your problem. – PatrickLu-MSFT Sep 16 '19 at 10:04
  • In the manage workspaces screenshot in your answer. Wouldn't it only show the workspaces setup on that computer? And am I correct that the workspaces are stored centrally on the Microsoft Dev ops server. I suppose my real queston is what causes error `The workspace [WORKSPACE];[OWNER] does not exist.` – DreamTeK Sep 16 '19 at 10:06
  • @DreamTeK Sorry for my screenshot which didn't present important part clearly. There is an option "Show Remote Workspaces". If you check this, you will be able to **view all the workspaces you own** (including those on other computers). ` And am I correct that the workspaces are stored centrally on... Server.` Not, workspaces are stored separately on any dev machine which you created. Besides if you want to delete **other user created/hosted workspace**, no matter in your own develop machine or another machine, you need to use command line `tf workspace /delete ws_3_3;username or ID` – PatrickLu-MSFT Sep 18 '19 at 10:25
  • @DreamTeK `I suppose my real queston is what causes error The workspace [WORKSPACE];[OWNER] does not exist. ` This is the key problem here, if TFS could detect that workspace properly, then it shouldn't be a issue. There are multiple reasons, for example you migrated to Azure from old TFS, that work space maybe obsoleted, the owner of workspace maybe not in your organization any more, there is some data corrupted for this workspace in database... and so on. Besides, you could share your solution here and mark it which will also help others in the community. – PatrickLu-MSFT Sep 18 '19 at 10:29
  • 1
    Thanks agin for the follow up and a top tip. I don't actually have a solution to my exact issue but you did answer the initial question so I will mark it as resolved. The owners of the workspaces are no longer part of the organisation anymore which could be the root cause but I assumed an administrator would still have suitable privilages to delete them. – DreamTeK Sep 19 '19 at 07:48
2

I recently had some issues deleting workspaces as the user who owned the workspace had left, so validation was failing to recongise their account.

This post introduced me to the XML output from the tf workspaces command; enabling me to get the underlying id of the user and delete the workspace using that.

Here's a PowerShell wrapper that I used to delete all workspaces for the user:

Set-Alias -Name 'tf' -Value 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe' # amend path so it points to your tf.exe file

# fetch a list of all workspaces and store them in an xml variable
$x = [xml](tf workspaces /computer:* /owner:* /format:xml)

# determine who we want to delete (this is used in our filter later; to delete all, just skip the filter
$userToDelete = 'Someone@example.com'

# for each workspace 
# take those where the owner's display name matches our target user
# then delete that workspace (I've left prompts enabled, so you can manually validate things; add /noprompt to avoid that
$x.Workspaces.Workspace | ?{$_.ownerdisp -eq $userToDelete} | %{tf vc workspace /delete "$($_.name);$($_.owner)"}

More info on available options in the MS Docs; so you can tweak the above per your exact requirements.

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178