TFS tf branch command error: no appropriate mapping exists for - tfs

I'm trying to use tf branch, but get this error:
no appropriate mapping exists for $/main_folder/folderB/folder1
below is my command:
tf branch $/main_folder/folderA/folder1/file.sql $/main_folder/folderB/folder1
Any ideas why?

The branch command copies an item or set of items, including metadata and version control history, from one location to another in the Team Foundation version control server and in the local workspace.
According to above error info, you also need to map your $/main_folder/folderB/folder1 path to your local workspace. Then try to perform the command again.
More detail tutorial about how to use this command please refer this official tutorial: Branch Command
A sample full command in cmd with using tf.exe branch command for your reference:
tf branch $/ScrumProject/TestCaseProject $/ScrumProject/Test /w:WPATRICK-W10

Related

TF.exe label - Workspace mapping required when creating a label for a server item?

In my TFS release i added a script to create a label when a certain environment succeeds.
This label is apply on a given server item and for a specific Changeset.
The TF.exe command looks like this:
tf.exe label Main-Approved $/MyProject/Main /recursive /version:C124730 /comment:"Approved by Main Release" /collection:http://tfsserver:port/tfs/MyCollection
However when run from the release i get the following error message return by TF.exe:
Error: There is no working folder mapping for D:\Agent-Default_work\r144\a\by.
Running this exact command localy works fine and creates the label.
I don't understand why i would need to create a workspace and some folder mapping in order to apply a label on a Server item (using $/...) for a specific changeset?
Any help would be appreciated.
Thanks!
So i was using a Python script to run the command.
I tried changing it to a powershell script and it works.
My guess is that in python the strings were passed incorrectly someone. I feel like the workspace 'by' was in fact my command wrongly parsed by the intepreter and considered an argument in tf.exe.

Exclude Files/Folder during TF get using command line

I have below mapped folder in local with TFS version control.
TFS version control folder ==> $/A/B/C
Local mapped folder ==> D:\MyFolder
Now from the command prompt, Getting all the latest files using below command
tf get D:\MyFolder /recursive /noprompt
Is there any way to exclude certain files/Folders while getting from TFS using the command line?
Thanks in advance
There isn’t ignore/exclude parameter in the tf get command line, but you can use specify the file/folder you want instead to use just get, for example tf get 314.cs.
In addition, you can cloak the files from the workspace: tf workfold /cloak (Team Foundation source control serverfolder|localfolder) [/workspace: workspacename] [/s:servername].
Another option - to ignore certain files you can add .tfignore file to the repository.

How to work with tfs files from code?

I have a desktop application to modify some xml files that are under source control. The program should be able to get the files, modify them and make a checkin. I already know how to do all that with tf; however, I don't know how to run the developer command prompt for visual studio using code. Also, the program will be installed in computers that doesn't have visual studio; therefore, they won't have the tf command anywhere. Taking into account all that, what would be the best way to run the following commands?
mkdir C:\Temp\PROGRAM
cd C:\Temp\PROGRAM && tf workspace /new /noprompt PROGRAM /collection:"http://myserver:8080/tfs/mycollection"
cd C:\Temp\PROGRAM && tf workfold /map $/my/server/route/to/map C:\Temp\PROGRAM
cd C:\Temp\PROGRAM && tf get
I know that there are some libraries to work with tfvc, but I haven't used them and don't seem as clear as running the commands. Any solution that manage to do the same as the commands above will be welcomed.
Create workspace
Map a folder from the server to a local folder
Download (checkout) all files in that folder (doesn't need to be recursive)
If possible to include in the solution:
Make checkin of files changed
EDIT
The code that I finally used is this
static void Load(string local, string server, Uri urlCollection)
{
Directory.CreateDirectory(local);
Workspace workspace = GetWorkspace(urlCollection, "MyWorkspaceName");
workspace.Map(server, local);
workspace.Get();
}
static Workspace GetWorkspace(Uri urlCollection, string name)
{
VersionControlServer vcs = new TfsTeamProjectCollection(urlCollection)
.GetService<VersionControlServer>();
try
{ return vcs.GetWorkspace(name, vcs.AuthorizedUser))}
catch(Exception)
{ return vcs.CreateWorkspace(name, vcs.AuthorizedUser)); }
}
According to your description, you want to pull down files from TFS server and then check in changed files programmatically.
You could use TFS client API to achieve this. Suggest you go through Buck Hodges's blog which shows how to create a workspace, pend changes, check in those changes.
Please refer Team Foundation Version Control client API example for TFS 2010 and newer
As for how to get files from TFS, there are also multiple samples in web portal, suggest you use the VersionControlServer.GetItem Method
Examples of usage:
// Get the latest Item for local path "C:\projects\myfiles.cs"
Item item1 = versionControlServer.GetItem("C:\projects\myfiles.cs");
// Get ItemId = 12345 for changesetId = 54321
Item item2 = versionControlServer.GetItem(12345,54321);
// Get the latest Item for server path "$/ProjectName/myfile.cs"
Item item1 = versionControlServer.GetItem("$/ProjectName/myfile.cs", VersionSpec.Latest);
You could also select a history version of source code to pull down, for the entire code, please refer below tutorials: Team Foundation Server API: Programmatically Downloading Files From
Source Control
Another way is using powershell script to handle this, please take a look here: Download files from TFS server with PowerShell
You can install on the computers the Team Explorer Everywhere, it gives you the ability to use TFS command line (the "tf" commands) without Visual Studio.

TFS - Getting all the change sets included in the last get

I am creating a batch build script.
I need a tfs cmd command to print all the change sets included in my get.
i failed to google it so far, appreciate any help.
I found a solution.
You can use the tf history command, you can compare the history of the local workbench vs the server.
Try this command:
tf history xxx.sln /noprompt /v:Cxx~W
Cxx: Get the changset of the time you would do the last get.
W: Specifies the version in your workspace.(Current)

TFS Workspace Cache

I appear to have some problems with my workspace cache. When I type:
tf workfold
In my workspace directory, I get the error:
Unable to determine the workspace
This article seems to imply that it’s a problem with the cache. Being cautious, I tried removing a single workspace:
tf workspaces /remove:WORKSPACENAME /server:servername
This seemed to work (that is, the command succeeds), because if I do it a second time it fails. However, when I issue:
tf workspaces
It still lists this workspace, and I still get the error.
Can anyone give me any guidance of the next step here? I assume what I’m deleting it the cache for the workspace and not the workspace itself, do I need to clear all my workspaces for this to work? If so, why might this make any difference?
Try running below command to refresh the cache:
tf workspaces /s:http://tfs-server:8080
this might be a daft question but are you running the tf workspaces command from a folder that's mapped to the workspace? e.g. your workspace mapping is something like $/MyTeamProject/Source -> c:\source
when you open your command prompt you should cd c:\source before running tf workspaces
You can try this one to delete the workspace:
tf workspace login:[your login credentials] - delete workspacename -collection:[collection URL]
example:
tf workspace login:US\\saket.kumar - delete saketworkspace1 -collection:https://tfs1101.client.com/tfs/CTS

Resources