0

I'm using tf.exe to perform TFS source control tasks - mapping folders, getting files. The current folder is mapped in a workspace, I've checked. The mapping is created programmatically, then tf is invoked.

Whenever I run the code on a new machine, I'm getting the following message:

Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collection:TeamProjectCollectionUrl'.

If I perform that command, it clears things up and everything works from now on. However, what exactly does it do, and how can I do the same using TFS API?

The docs say it "updates cached information about a user name or computer name change on the server that is running Visual Studio Team Foundation Server." I don't get it - where's the cache? What do they consider a computer name change?

Calling Workspace.Refresh() or Workspace.Update() doesn't help.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281

1 Answers1

3

The workspace cache is kept per (major) version of the client, and those do not interoperate between versions. (Since the Visual Studio/TFS 2015 workspace cache may be in a different format than the Visual Studio/TFS 2013 workspace cache, and Visual Studio 2013 may not be able to read that new version in a forward-compatible way.)

So if you're using the Team Foundation Server 2013 SDK to create a new workspace, it will create the workspace on the server and put that information in the workspace cache so that subsequent calls will have that information without having to read it from the server.

But if you then use the tf.exe included with Visual Studio 2015, it will not find that workspace in the cache. It will need to connect to the server to get a list of workspaces - which it will then cache for future use, but again, in the TFS 2015 cache location.

Broadly speaking, you need to use the same version of the SDK as the command line interface. Other alternatives are to just create the workspace using the tf.exe command line interface and not use the API at all. Or to always use the API and never use tf.exe. This problem only occurs when you mix and match clients.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • Afraid not. Tf.exe says it's v11, and the TFS API DLLs the process is using are v11, too. Of all Visual Studio components, the machine only has Team Explorer 2012. – Seva Alekseyev Aug 31 '15 at 14:38
  • @SevaAlekseyev In that case: are you specifying the URL identically between invocations? Are you running as different users? Can you write to the workspace cache? What's the difference between the workspace cache before and after each client execution? (The workspace cache is at `%LOCALAPPDATA%\Microsoft\Team Foundation\\Cache`.) – Edward Thomson Aug 31 '15 at 15:54
  • Same user. I'm not specifying URL on the tf.exe invokation - I expect it to pick up the context from the current folder. I'll check the cache... – Seva Alekseyev Aug 31 '15 at 16:22
  • Funny, I've deleted and recreated the workspace, and tf picked it up now. Oh well... – Seva Alekseyev Aug 31 '15 at 16:33