4
votes

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?
2
If you not launch VS and re run the first command the deleted workspace exist? in the VS UI can you success to delete the workspace completely?Shayki Abramczyk
According to your command line, did you try to delete a Azure DevOps Service not TFS workspace?PatrickLu-MSFT
@ShaykiAbramczyk Yes the workspace shows as deleted until I launch VS again.DreamTeK
@PatrickLu-MSFT I believe the command I used deletes the workspaces. The delete command does remove the workspace from the list after running.DreamTeK
@DreamTeK In the past it worked well in VS2019? do you have the latest version of VS2019?Shayki Abramczyk

2 Answers

5
votes

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.

2
votes

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 = '[email protected]'

# 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.