How to programmatically detect deleted files? - tfs

In Team Foundation, you can ask Team Explorer to show deleted files by doing this:
Tools > Options > Source Control >
Visual Team Foundation Server > Show
deleted items in the Source Control
Explorer.
My question is how do you do the same thing programmatically?
I am developing a synchronisation tool, and I need to detected deleted files in TFS. Workspace.Get(...) returns only non-deleted files.
Any idea how I can achieve that?

Go to the Visual Studio folder in your start menu and start up a Visual Studio Command Prompt from the "Visual Studio Tools" subfolder.
The command you want to run is:
tf dir /server:myserver $/myproject /recursive /deleted
(where myserver and myproject are your server and project)
use "tf help" for general info, "tfs help dir" for more help on this command, or google on "tf.exe" for more info.

The VersionControlServer.QueryHistory API will give you access to the changesets which will contain all version control operations including deletes.

Related

VS 2019 unable to add a file to TFS

I'm currently using VS 2019 Professional and TFS as my source control. I've created an XML file on Notepad++ and placed it in a location that TFS is aware off in file explorer.
Usually with older version of VS, I would be able to right click the file and select "Add" under the TFS extension. From what I can see, this option is no longer available for 2019: Team Foundation Server Power Tools for Visual Studio 2019
I've tried going down the path of using the dev command prompt and set a system variable with the
name: tfs
value: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe
and once I attempt to run the following command: tfs add myFile.XML with the CD path set to where I want the file added, I receive the error:
'tfs' is not recognized as an internal or external command,
operable program or batch file.
Was hoping to see if there's anything I was doing wrong here or if there's another way I can go around to achieve adding a file?
Just in case anywhere stumbles across this in the future, on VS if you go to the Source Control Explorer Screen, navigate to the directory you'd like the file added to then right click anywhere on the screen and select Add items to folder

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.

How to find a project within the TFS 2010 Source control?

I have some project A which is checked in to some folder within the Team Project long time back by somebody else. I have to where it is located. do i have any command to search the file or project file within the team project. I have many team projects within the project collection.
If you're searching for a file and know the name of it, you can do it from the commandline (Visual Studio Command Prompt) using tf.exe.
tf dir $/TeamProjectName/FileName.csproj /recursive /s:http://tfsserver:8080/tfs/CollectionName

Can't remove workspace from TFS

I want to add my project from Visual Studio 2012 to my TFS server, but it says the path is already mapped for workspace pc;administrator (this is a local workspace).
I have tried the command tool tf but it says that there are no workspaces, so I can't delete the workspace that is conflicting.
I'm running Windows 8 with Visual Studio 2012. TFS is on a windows server 2012.
The problem is that the current project location, the folder on your physical machine, is mapped to a different TFS server. To add it to source control you need to move it to a physical location not associated with a TFS server.
Edit
To remove the offending workspace:
1) Use the "Team" menu to connect to the TFS Server that you do NOT want to be mapped to
2) Use ctrl+q --> workspaces to access the workspaces menu
3) Remove the workspace
4) Change to the TFS Server you WANT to be mapped to using the "Team" menu again
5) ctrl+q --> workspaces
6) Add a new workspace
Try any of these steps out. Some of them may not be applicable to you.
To clear up "cached workspace" and remove workspace mapping.
On Control Panel > User > Credential Manager
Remove Windows Account and Generic Account that points to TFS.
How can I change the default credentials used to connect to Visual Studio Online (TFSPreview) when loading Visual Studio up?
On IE, remove cached password.
http://www.jayway.com/2012/12/17/changing-tfs-credentials-in-visual-studio-2012/
Remove stored username/password:
http://blogs.msdn.com/b/visualstudioalm/archive/2012/08/29/clearing-the-credentials-for-connecting-to-a-team-foundation-server.aspx
rundll32.exe keymgr.dll,KRShowKeyMgr
Delete workspace. On VS2012 command line, run the following:
tf.exe workspace /delete workspacename;owner /server:serveraddress
http://mycomputeradventures.blogspot.com/2012/01/removing-tfs-workspaces-from-old-users.html
Clear Up cached workspace mapping. On VS2012 command line, run the following:
tf.exe workspaces /remove:* (or /s:http//oldserver:8080)
http://blogs.msdn.com/b/buckh/archive/2006/09/12/path-is-already-mapped-in-workspace.aspx
if you use Visual studio 2012 go
C:\Users{UserName}\AppData\Local\Microsoft\Team Foundation\4.0\Cache
or if it is Visual studio 2013 go
C:\Users{UserName}\AppData\Local\Microsoft\Team Foundation\5.0\Cache
Remove all things under it.
Simplest way to do this is to go to your AppData and delete the TFS cache (depending on the version 3.0 or 4.0)
C:\Users{UserName}\AppData\Local\Microsoft\Team Foundation\3.0\Cache
or
C:\Users{UserName}\AppData\Local\Microsoft\Team Foundation\4.0\Cache
First we will check the list of workspaces from VS 2015 Developer command prompt,
Ex - tf workspaces /owner:*
Now we will get the xml format from VS 2017 Developer command prompt which will have ‘owner id’ for the particular workspace,
Example 1 - tf.exe workspaces /owner:* /computer:ComputerName
/collection:https://YOUR-TFS-URL.visualstudio.com /format:xml
We can now delete the workspace for the particular user,
Example 1- Tf workspace /delete ComputerName;email#email.com
/server:"https://URL.visualstudio.com"
OR
Example 2 - Tf workspace /delete ComputerName;1e178c77-bb8b-6f05-bf99
/server:https://URL.visualstudio.com
(Where 1e178c77-bb8b-6f05-bf99 is ID of the workspace which you get from Step 2 XML
format)
Again we will check the list of workspaces from VS 2015 Developer command prompt,
Ex - tf workspaces /owner:*
Well I couldnt find my troublesome workspace, which prompted me to copy the local code folder into another name and I created a new workspace mapping that folder.
Next up I added the new solution to the TFS via VS 2012 using Add Source Control.

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