简体   繁体   中英

C# TFS Workspace.PendADD No working mapping for the folder

I am trying to add a file to TFS through C# . Here is my code.

 Workspace workspace = versionControl.QueryWorkspaces(Environment.MachineName, versionControl.AuthorizedUser, Environment.MachineName).SingleOrDefault();
        if (workspace == null)
        {
            w("No workspace configured");
            return;
        }

        //String topDir = null;

       var troubleshooter = workspace.GetWorkingFolderForLocalItem("LocalPath");  

workspace.PendAdd("Filepath", true);

Its weird that when I call workspace.GeWorkingFolderForLocalItem it works fine and gets the folder mapping. Issue arises when I try to PendADD a file in TFS from the same path then Fatal Error occures stating that no Working mapping found for the "LocalPath".

Any Guess?

Seems like the problem was in the cache for VersionControlServer. Cache was not fully updated that is why "GetWorkingFolderforServerItem" was working well and PendAdd was not. PendAdd Use cache. Following command did the trick.

            Workstation.Current.EnsureUpdateWorkspaceInfoCache(versionControl, versionControl.AuthorizedUser);

According to your error info, make sure your workspace mappings are setup correctly: otherwise, calling workspace.PendAdd recursively will not, in fact, add anything. Please see the detail explanation in the Edward Thomson 's answer of this question: Calls to `Workspace.PendAdd` not adding items

And here is another blog from MSDN show how to create a workspace, pending changes, check in those changes for your reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM